<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBS: вставить строку из .doc в .txt]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=10076&amp;type=atom" />
	<updated>2014-10-28T11:04:26Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=10076</id>
		<entry>
			<title type="html"><![CDATA[Re: VBS: вставить строку из .doc в .txt]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=87815#p87815" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>Только убрал лишние пробелы (не очень красиво выходило).</p></blockquote></div><p>В конце «красной» строки? Внутри?</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2014-10-28T11:04:26Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=87815#p87815</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: вставить строку из .doc в .txt]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=87814#p87814" />
			<content type="html"><![CDATA[<p>Большое спасибо! Получилось то, что хотел! Только убрал лишние пробелы (не очень красиво выходило).</p>]]></content>
			<author>
				<name><![CDATA[siv14]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29700</uri>
			</author>
			<updated>2014-10-28T10:37:04Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=87814#p87814</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: вставить строку из .doc в .txt]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=87809#p87809" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>alexii пишет:</cite><blockquote><p>&nbsp; В общем, я выбрал второй вариант.</p></blockquote></div><p>Я это и имел ввиду. Спасибо. Буду пробовать.</p>]]></content>
			<author>
				<name><![CDATA[siv14]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29700</uri>
			</author>
			<updated>2014-10-28T04:49:38Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=87809#p87809</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: вставить строку из .doc в .txt]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=87804#p87804" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>1. Вставлятся в текстовый файл должна выкрашеная строка.</p></blockquote></div><p>Опять обошли ответ. На что ориентируемся со слова «от …» — на 40 символов или, не считая — до конца строки? В общем, я выбрал второй вариант.</p><p>Пробуйте:<br /></p><div class="codebox"><pre><code>Option Explicit

Const wdFindContinue = 1

Const wdParagraph = 4
Const wdCharacter = 1
Const wdExtend = 1


Dim strSourceFile
Dim strDestFile

Dim strSorceFilePattern
Dim strDestFilePhrase


Dim strText
Dim strContent

Dim boolFound


strSourceFile = &quot;E:\Песочница\0404\test\Список.doc&quot;
strDestFile   = &quot;E:\Песочница\0404\test\Test22.txt&quot;

strSorceFilePattern = &quot;от [0-9]{2}.[0-9]{2}.[0-9]{4} @№&quot;
strDestFilePhrase   = &quot;Auto File Transfer&quot;


With WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;)
    If .FileExists(strSourceFile) Then
        If .FileExists(strDestFile) Then
            boolFound = False
            
            With WScript.CreateObject(&quot;Word.Application&quot;)
                &#039;.Visible = True
                
                With .Documents.Open(strSourceFile)
                    With .Content.Find
                        .ClearFormatting
                        .Text = strSorceFilePattern
                        
                        .Forward = True
                        .Wrap = wdFindContinue
                        
                        .Format = False
                        .MatchCase = False
                        .MatchWholeWord = False
                        .MatchAllWordForms = False
                        .MatchSoundsLike = False
                        .MatchWildcards = True
                        
                        With .Replacement
                            .Text = &quot;&quot;
                            .ClearFormatting
                        End With
                        
                        If .Execute() Then
                            With .Parent
                                .EndOf wdParagraph, wdExtend
                                .MoveEnd wdCharacter, -1
                                strText = .Text
                            End With
                            
                            boolFound = True
                        End If
                    End With
                    
                    .Close
                End With
                
                .Quit
            End With
            
            If boolFound Then
                With .OpenTextFile(strDestFile)
                    strContent = .ReadAll()
                    .Close
                End With
                
                If InStr(1, strContent, strDestFilePhrase, vbTextCompare) &gt; 0 Then
                    With .CreateTextFile(strDestFile, True)
                        .Write Replace(strContent, strDestFilePhrase, strText)
                        .Close
                    End With
                Else
                    WScript.Echo &quot;Can&#039;t find phrase [&quot; &amp; strDestFilePhrase &amp; &quot;] in destination file [&quot; &amp; strDestFile &amp; &quot;].&quot;
                    WScript.Quit 4
                End If
            Else
                WScript.Echo &quot;Can&#039;t find any text by pattern [&quot; &amp; strSorceFilePattern &amp; &quot;] in source file [&quot; &amp; strSourceFile &amp; &quot;].&quot;
                WScript.Quit 3
            End If
        Else
            WScript.Echo &quot;Can&#039;t find destination file [&quot; &amp; strDestFile &amp; &quot;].&quot;
            WScript.Quit 2
        End If
    Else
        WScript.Echo &quot;Can&#039;t find source file [&quot; &amp; strSourceFile &amp; &quot;].&quot;
        WScript.Quit 1
    End If
End With

WScript.Quit 0
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2014-10-27T22:45:26Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=87804#p87804</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: вставить строку из .doc в .txt]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=87778#p87778" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>alexii пишет:</cite><blockquote><p><strong>siv14</strong>, потерпите ещё немного. В процессе.</p><p>... но строка выкрашена в красный до конца абзаца. Может, на это ориентироваться?</p></blockquote></div><p>Добрый день!<br />Теперь все по-порядку:<br />1. Вставлятся в текстовый файл должна выкрашеная строка.<br />2. Вставляться выкрашеная строка должна вместо - Auto File Transfer.<br />3. Ориентироваться можно на номер строки или на текст «Auto File Transfer», они постоянны.<br />4. Место замены определяем по тексту «Auto File Transfer».</p>]]></content>
			<author>
				<name><![CDATA[siv14]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29700</uri>
			</author>
			<updated>2014-10-27T13:28:15Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=87778#p87778</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: вставить строку из .doc в .txt]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=87777#p87777" />
			<content type="html"><![CDATA[<p><strong>siv14</strong>, потерпите ещё немного. В процессе.</p><p>Попутно вопросы: изначально речь шла про «определённое количество символов», далее уточнялось про «40». Из самого приложенного документа количество не ясно, но строка выкрашена в красный до конца абзаца. Может, на это ориентироваться?</p><p>Далее, в приложенном текстовом файле строка «Subject: Auto File Transfer». Вы пишете и «в текстовый документ, в определенную строку», и «в текстовый файл вместо Auto.... надо вставить эти символы». Так на что ориентируемся — на номер строки или на текст «Auto»? Вставляем вместо только «Auto» или вместо «Auto File Transfer»? Опять же, место замены определяем по количеству символов или ориентируемся на текст «Subject: »?</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2014-10-27T10:42:33Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=87777#p87777</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: вставить строку из .doc в .txt]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=87776#p87776" />
			<content type="html"><![CDATA[<p>Добрый день! <br />Нашел на форуме скрипт поиска строки в текстовом файле. Он подошел к моим условиям, но там где &quot;Вставка из Word&quot;, не пойму что надо сделать. По идее надо найти строку в Word&#039;е, скопировать, присвоить ее переменной и затем вставить в текст. Но каким образом не пойму. Помогите пожалуйста.</p><div class="quotebox"><blockquote><p>Option Explicit</p><p>Dim strSourceFile<br />Dim arrContent<br />Dim strLine</p><br /><p>strSourceFile = &quot;d:\Test22.txt&quot;</p><p>With WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;)<br />&nbsp; &nbsp; If .FileExists(strSourceFile) Then<br />&nbsp; &nbsp; &nbsp; &nbsp; With .OpenTextFile(strSourceFile)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arrContent = Split(.ReadAll(), vbCrLf)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Close<br />&nbsp; &nbsp; &nbsp; &nbsp; End With<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; With WScript.CreateObject(&quot;VBScript.RegExp&quot;)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .IgnoreCase = True<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For Each strLine In arrContent<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Pattern = &quot;^.*(Auto).*$&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If .Test(strLine) Then<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WScript.Echo &quot;Вставка из Word&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br />&nbsp; &nbsp; &nbsp; &nbsp; WScript.Echo &quot;Нет такой строки&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; WScript.Quit 1<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next<br />&nbsp; &nbsp; &nbsp; &nbsp; End With<br />&nbsp; &nbsp; Else<br />&nbsp; &nbsp; &nbsp; &nbsp; WScript.Echo &quot;Source file [&quot; &amp; strSourceFile &amp; &quot;] not found.&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; WScript.Quit 1<br />&nbsp; &nbsp; End If<br />End With</p><p>WScript.Quit 0</p></blockquote></div>]]></content>
			<author>
				<name><![CDATA[siv14]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29700</uri>
			</author>
			<updated>2014-10-27T09:20:01Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=87776#p87776</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: вставить строку из .doc в .txt]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=87775#p87775" />
			<content type="html"><![CDATA[<p>Вот мой http://rghost.net/58736695 Test.rar</p>]]></content>
			<author>
				<name><![CDATA[siv14]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29700</uri>
			</author>
			<updated>2014-10-27T06:34:56Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=87775#p87775</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: вставить строку из .doc в .txt]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=87774#p87774" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>alexii пишет:</cite><blockquote><p>выложите последний на RGhost.</p></blockquote></div><p>У меня не выходит разместить файл в RGhost, поэтому я его приаттачил здесь. Не будет это большой ошибкой?</p>]]></content>
			<author>
				<name><![CDATA[siv14]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29700</uri>
			</author>
			<updated>2014-10-27T06:18:09Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=87774#p87774</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: вставить строку из .doc в .txt]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=87699#p87699" />
			<content type="html"><![CDATA[<p>Количество символов - 40, в текстовый файл вместо Auto.... надо вставить эти символы. Количество строк в .txt постоянно.</p>]]></content>
			<author>
				<name><![CDATA[siv14]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29700</uri>
			</author>
			<updated>2014-10-24T10:32:36Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=87699#p87699</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: вставить строку из .doc в .txt]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=87698#p87698" />
			<content type="html"><![CDATA[<p>Конкретная реализация будет явным образом зависеть от деталей техзадания.</p><p>Упакуйте образцы документа и текстового файла в архив, выложите последний на RGhost. Укажите конкретное значение «определённого количества символов», что это за символы, как они соотносятся с найденной строкой, что делать, если их окажется меньше. Укажите конкретное значение «определённой строки», а также, что делать, если строк в текстовом файле окажется меньше.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2014-10-24T09:43:24Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=87698#p87698</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[VBS: вставить строку из .doc в .txt]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=87697#p87697" />
			<content type="html"><![CDATA[<p>Добрый день! Просмотрел форум, но не нашел подходящей темы (или плохо смотрел). Надо найти в документе Word строку (дата № ) и вставить определенное количество символов в текстовый документ, в определенную строку. Как можно решить эту задачу?</p>]]></content>
			<author>
				<name><![CDATA[siv14]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29700</uri>
			</author>
			<updated>2014-10-24T09:28:12Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=87697#p87697</id>
		</entry>
</feed>
