<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; JScript: Открытие файла MS Word]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=6022&amp;type=atom" />
	<updated>2022-02-14T13:49:33Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=6022</id>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Открытие файла MS Word]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=152181#p152181" />
			<content type="html"><![CDATA[<p><strong>megaroweb</strong>, добро пожаловать на форум! Ознакомьтесь, пожалуйста, с <a href="https://forum.script-coding.com/misc.php?action=rules">Правилами</a>, отредактируйте свои посты. Обратите внимание на оформление <a href="https://forum.script-coding.com/misc.php?action=rules#code-formatting">кода</a> и <a href="https://forum.script-coding.com/misc.php?action=rules#links-formatting">ссылок</a>, заглавные <a href="https://forum.script-coding.com/misc.php?action=rules#literacy">буквы</a> в начале и точки в конце предложений.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2022-02-14T13:49:33Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=152181#p152181</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Открытие файла MS Word]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50218#p50218" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Крепыш пишет:</cite><blockquote><div class="quotebox"><cite>Spy00000 пишет:</cite><blockquote><p><strong>Крепыш</strong> у вас сервис-пак 2 на офис установлен?<br />Не, нету. Windows 7 и Office 2007 без SP.</p></blockquote></div></blockquote></div><p>Стоит попробовать поставить.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-07-27T09:49:10Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50218#p50218</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Открытие файла MS Word]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50216#p50216" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Spy00000 пишет:</cite><blockquote><p><strong>Крепыш</strong> у вас сервис-пак 2 на офис установлен?</p></blockquote></div><p>Не, нету. Windows 7 и Office 2007 без SP.</p><p>Сейчас проверил: на Windows XP SP2 и MS Office 2010 открывается на первом плане и поле &quot;Имя файла&quot;заполнено. Вот как-то так.</p>]]></content>
			<author>
				<name><![CDATA[Крепыш]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=20359</uri>
			</author>
			<updated>2011-07-27T08:24:37Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50216#p50216</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Открытие файла MS Word]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50202#p50202" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Крепыш пишет:</cite><blockquote><p>Окно MS Word открывается на первом плане, но заполнить поле &quot;Имя файла&quot; так и не получилось.</p></blockquote></div><p>Судя по <a href="http://support.microsoft.com/kb/926888">вот этой статье</a> это проблема 2007 офиса, если он установлен на Vista и на, исходя из<br /></p><div class="quotebox"><cite>Крепыш пишет:</cite><blockquote><p>Попрбовал: Word открывается позади и мигает кнопкой на панели задач (MS Windows 7, MS Office 2007)</p></blockquote></div><p>Windows 7. Про hotfix или workaround в статье что-то ничего не сказано.<br /><strong>Крепыш</strong> у вас сервис-пак 2 на офис установлен?</p>]]></content>
			<author>
				<name><![CDATA[Spy00000]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27060</uri>
			</author>
			<updated>2011-07-26T20:10:22Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50202#p50202</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Открытие файла MS Word]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50200#p50200" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>Окно MS Word открывается на первом плане, но заполнить поле &quot;Имя файла&quot; так и не получилось.</p></blockquote></div><p>Сожалею. У меня на коде из <a href="http://forum.script-coding.com/viewtopic.php?pid=50124#p50124">#8</a>:<br /></p><div class="codebox"><pre><code>Option Explicit

Const msoFileDialogOpen  = 1
Const wdDoNotSaveChanges = 0

Dim strText
Dim strPath
Dim strFileName


strPath     = &quot;C:\Documents and Settings\User\Мои документы\&quot;
strFileName = &quot;Some*.doc&quot;


With WScript.CreateObject(&quot;Word.Application&quot;)
    .Visible = True
    .Activate
    
    With .FileDialog(msoFileDialogOpen)
        .AllowMultiSelect = False
        .InitialFileName  = strPath &amp; strFileName
        
        If .Show() = -1 Then
            With .Application.Documents.Open(.SelectedItems.Item(1))
                strText = .Range.Text
                .Close wdDoNotSaveChanges
            End With
        End If
    End With
    
    .Quit wdDoNotSaveChanges
End With

WScript.Echo strText

WScript.Quit</code></pre></div><p>и окно на переднем плане, и маска работает:<br /><a href="http://img283.imagevenue.com/img.php?image=97414_SomePatternDocs_122_363lo.jpg"><span class="postimg"><img src="http://img283.imagevenue.com/loc363/th_97414_SomePatternDocs_122_363lo.jpg" alt="http://img283.imagevenue.com/loc363/th_97414_SomePatternDocs_122_363lo.jpg" /></span></a></p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-07-26T16:25:13Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50200#p50200</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Открытие файла MS Word]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50194#p50194" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>var msoFileDialogOpen  = 1;
var wdDoNotSaveChanges = 0;
var objFSO = WScript.CreateObject(&#039;Scripting.FileSystemObject&#039;);
var strPath = objFSO.GetParentFolderName(WScript.ScriptFullName);
var strFileName = &#039;*.doc&#039;;

with (WScript.CreateObject(&#039;Word.Application&#039;))
{
  Visible = true;
  Activate();
  WScript.CreateObject(&#039;WScript.Shell&#039;).AppActivate(&#039;Microsoft Word&#039;);
  with (FileDialog(msoFileDialogOpen))
  {
    AllowMultiSelect = false;
    InitialFileName  = objFSO.BuildPath(strPath, strFileName);
    Filters.Clear();
    Filters.Add(&#039;Все файлы&#039;, &#039;*.*&#039;, 1);
    Filters.Add(&#039;Документы Word&#039;, &#039;*.doc; *.docx&#039;, 2);
    FilterIndex = 2;
    if (Show() == -1)
      with (Application.Documents.Open(SelectedItems.Item(1)))
      {
        var strText = Range().Text;
        Close(wdDoNotSaveChanges)
      }
  }
  Quit(wdDoNotSaveChanges)
}
WScript.Echo(strText)</code></pre></div><p>Окно MS Word открывается на первом плане, но заполнить поле &quot;Имя файла&quot; так и не получилось.</p>]]></content>
			<author>
				<name><![CDATA[Крепыш]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=20359</uri>
			</author>
			<updated>2011-07-26T12:45:06Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50194#p50194</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Открытие файла MS Word]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50176#p50176" />
			<content type="html"><![CDATA[<p><strong>Крепыш</strong>, к сожалению, у меня нет доступа к Microsoft Office 2007. Возможно, там сменилась объектная модель в этом отношении. У меня-то как раз маска:<br /></p><div class="codebox"><pre><code>strPath     = &quot;C:\Temp\&quot;
strFileName = &quot;*.doc&quot;
…
        .InitialFileName  = strPath &amp; strFileName</code></pre></div><p>отрабатывает.<br /></p><div class="quotebox"><cite>Крепыш пишет:</cite><blockquote><p>Word открывается позади и мигает кнопкой на панели задач</p></blockquote></div><p>Значит, таковы настройки Вашей ОС: «запретить «похищать» фокус у активного окна». Как раз вместо этого ОС мигает на панели задач кнопкой приложения, просящего активацию окна.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-07-25T13:39:30Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50176#p50176</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Открытие файла MS Word]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50173#p50173" />
			<content type="html"><![CDATA[<p>Попрбовал: Word открывается позади и мигает кнопкой на панели задач (MS Windows 7, MS Office 2007)<br />Маска для имени файла не применяется. А так хотелось, чтобы в поле &quot;Имя файла&quot; можно было задать маску, типа: &quot;*25.07.2011.doc&quot;.<br />Получилось только задать фильтр:</p><div class="codebox"><pre><code>    With .FileDialog(msoFileDialogOpen)
        .AllowMultiSelect = False
        .InitialFileName  = strPath
        .FilterIndex = 2

...</code></pre></div><p>или так:</p><div class="codebox"><pre><code>    With .FileDialog(msoFileDialogOpen)
        .AllowMultiSelect = False
        .InitialFileName  = strPath
        .Filters.Add &quot;Свой фильтр&quot;, &quot;*.doc; *.docx&quot;, 2
        .FilterIndex = 2

...</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Крепыш]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=20359</uri>
			</author>
			<updated>2011-07-25T12:22:47Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50173#p50173</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Открытие файла MS Word]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50124#p50124" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Крепыш пишет:</cite><blockquote><p>- окно word всё равно открывается позади</p></blockquote></div><p>У меня — на переднем плане. Хорошо, давайте попробуем ещё «углубить» (см. ниже).<br /></p><div class="quotebox"><cite>Крепыш пишет:</cite><blockquote><p>В диалоговом окне, например, путь по умолчанию для открытия файлов должен быть strPath, а имя файла strFileName. Какие именно - не важно, вопрос в другом: надо, чтобы можно было их задавать.</p></blockquote></div><p>Ясно. Пробуйте:<br /></p><div class="codebox"><pre><code>Option Explicit

Const msoFileDialogOpen  = 1
Const wdDoNotSaveChanges = 0

Dim strText
Dim strPath
Dim strFileName


strPath     = &quot;C:\Temp\&quot;
strFileName = &quot;*.doc&quot;


With WScript.CreateObject(&quot;Word.Application&quot;)
    .Visible = True
    .Activate
    
    With .FileDialog(msoFileDialogOpen)
        .AllowMultiSelect = False
        .InitialFileName  = strPath &amp; strFileName
        
        If .Show() = -1 Then
            With .Application.Documents.Open(.SelectedItems.Item(1))
                strText = .Range.Text
                .Close wdDoNotSaveChanges
            End With
        End If
    End With
    
    .Quit wdDoNotSaveChanges
End With

WScript.Echo strText

WScript.Quit</code></pre></div><div class="quotebox"><cite>Крепыш пишет:</cite><blockquote><p>…из другого активного в этот момент документа. Так?</p></blockquote></div><p>Откуда возьмётся другой активный документ при <em>единственном</em> открытом документе в <em>этом</em> экземпляре WinWord&#039;а? Впрочем, нынче сие уже не важно.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-07-23T06:23:51Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50124#p50124</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Открытие файла MS Word]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50115#p50115" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>alexii пишет:</cite><blockquote><p>Откажитесь от:<br /></p><div class="quotebox"><blockquote><p>…(в фоне)</p></blockquote></div><div class="codebox"><pre><code>With WScript.CreateObject(&quot;Word.Application&quot;)
    .Visible = True
    
    If .Dialogs(wdDialogFileOpen).Show() = -1 Then
        With .ActiveDocument
            …</code></pre></div></blockquote></div><p>Не помогло:<br />- неудобно<br />- окно word всё равно открывается позади</p><div class="quotebox"><cite>alexii пишет:</cite><blockquote><p>Не вижу ни «пути по умолчанию», ни символов маски в приведённом имени.</p></blockquote></div><p>В диалоговом окне, например, путь по умолчанию для открытия файлов должен быть <strong>strPath</strong>, а имя файла <strong>strFileName</strong>. Какие именно - не важно, вопрос в другом: надо, чтобы можно было их задавать.</p><div class="quotebox"><cite>alexii пишет:</cite><blockquote><div class="quotebox"><cite>smaharbA пишет:</cite><blockquote><p>не надо так делать &quot;ActiveDocument&quot; можно налететь</p></blockquote></div><p>Моя твоя не панимай.</p></blockquote></div><p>Я думаю, <strong>smaharbA</strong> хотел сказать, что таким образом скрипт может считать содержимое из другого активного в этот момент документа. Так?</p>]]></content>
			<author>
				<name><![CDATA[Крепыш]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=20359</uri>
			</author>
			<updated>2011-07-22T17:35:28Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50115#p50115</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Открытие файла MS Word]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50079#p50079" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Крепыш пишет:</cite><blockquote><p>1) Чтобы в диалоговом окне сразу был указан путь по умолчанию и маска файла (например, &lt;дата&gt;.docx)</p></blockquote></div><p>Не вижу ни «пути по умолчанию», ни символов маски в приведённом имени.<br /></p><div class="quotebox"><cite>Крепыш пишет:</cite><blockquote><p>2) При запуске скрипта диалоговое окно открывается позади того окна, из которого был запущен скрипт. Как вывести его на первый план?</p></blockquote></div><p>Откажитесь от:<br /></p><div class="quotebox"><blockquote><p>…(в фоне)</p></blockquote></div><div class="codebox"><pre><code>With WScript.CreateObject(&quot;Word.Application&quot;)
    .Visible = True
    
    If .Dialogs(wdDialogFileOpen).Show() = -1 Then
        With .ActiveDocument
            …</code></pre></div><div class="quotebox"><cite>smaharbA пишет:</cite><blockquote><p>не надо так делать &quot;ActiveDocument&quot; можно налететь</p></blockquote></div><p>Моя твоя не панимай.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-07-22T04:37:20Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50079#p50079</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Открытие файла MS Word]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50068#p50068" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>smaharbA пишет:</cite><blockquote><p>не надо так делать &quot;ActiveDocument&quot; можно налететь</p></blockquote></div><p>А так вот нормально будет?</p><div class="codebox"><pre><code>var FileName;
with (WScript.CreateObject(&#039;Word.Application&#039;)) {
  with (Documents.Open(FileName)) {
    var strText = Range().Text;
    Close(0)
  }
  Quit()
}
WScript.Echo(strText)</code></pre></div><p>Только надо как-то получить имя открываемого файла из диалогового окна открытия файлов.</p>]]></content>
			<author>
				<name><![CDATA[Крепыш]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=20359</uri>
			</author>
			<updated>2011-07-21T18:01:03Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50068#p50068</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Открытие файла MS Word]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50056#p50056" />
			<content type="html"><![CDATA[<p>не надо так делать &quot;ActiveDocument&quot; можно налететь</p>]]></content>
			<author>
				<name><![CDATA[smaharbA]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=2911</uri>
			</author>
			<updated>2011-07-21T12:25:31Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50056#p50056</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Открытие файла MS Word]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50054#p50054" />
			<content type="html"><![CDATA[<p><strong>alexii</strong>, спасибо!</p><p>Можно ли добавить?<br />1) Чтобы в диалоговом окне сразу был указан путь по умолчанию и маска файла (например, &lt;дата&gt;.docx)<br />2) При запуске скрипта диалоговое окно открывается позади того окна, из которого был запущен скрипт. Как вывести его на первый план?</p>]]></content>
			<author>
				<name><![CDATA[Крепыш]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=20359</uri>
			</author>
			<updated>2011-07-21T11:48:52Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50054#p50054</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JScript: Открытие файла MS Word]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=49986#p49986" />
			<content type="html"><![CDATA[<p>Примерно так:<br /></p><div class="codebox"><pre><code>Option Explicit

Const wdDialogFileOpen   = 80
Const wdDoNotSaveChanges = 0


Dim strText

With WScript.CreateObject(&quot;Word.Application&quot;)
    If .Dialogs(wdDialogFileOpen).Show() = -1 Then
        .Visible = False
        
        With .ActiveDocument
            strText = .Range.Text
            .Close wdDoNotSaveChanges
        End With
    End If
    
    .Quit wdDoNotSaveChanges
End With

WScript.Echo strText

WScript.Quit</code></pre></div>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-07-19T12:22:44Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=49986#p49986</id>
		</entry>
</feed>
