with my vbs ,
i want to open a word file and search different
string in this file when i find this string
i must create a new word file and put string in this file.
an idea ??
thanks

Re: work with a word doc file by Evertjan

Evertjan
Fri Feb 06 17:33:02 CST 2004

isabelle wrote on 07 feb 2004 in microsoft.public.scripting.vbscript:
> with my vbs ,
> i want to open a word file and search different
> string in this file when i find this string
> i must create a new word file and put string in this file.
> an idea ??

Do you want to build a MS Word Macro with VBA ?

Or cscript/wscript ?

Or in Internet explorer ?

Or sesverside scripting ?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Re: work with a word doc file by isabelle

isabelle
Sat Feb 07 05:16:43 CST 2004


> Do you want to build a MS Word Macro with VBA ?
>
> Or cscript/wscript ?
>
> Or in Internet explorer ?
>
i want to use a cscript/wscript (vbs)
thanks



Re: work with a word doc file by Peter

Peter
Sat Feb 07 15:17:02 CST 2004

Hi isabelle

Questions:

1. Are you always going to search for the same string, if no please provide a
sample of what your search string is. Is you need to search for more that one
string you need to specify that as well.
2. When you create a new Word document what's it's name. Is it's name derived
from the original?
3. Is it just the search string you want in your new Word document or is it
in fact the old document with the appropriate replacements made?


HTH + Cheers - Peter


"isabelle" <recup60@yahoo.fr> wrote in news:40242331$0$28134
$636a15ce@news.free.fr:

> with my vbs ,
> i want to open a word file and search different
> string in this file when i find this string
> i must create a new word file and put string in this file.
> an idea ??
> thanks
>
>


Re: work with a word doc file by isabelle

isabelle
Sun Feb 08 12:52:34 CST 2004


>
> Questions:
>
> 1. Are you always going to search for the same string, if no please
provide a
> sample of what your search string is. Is you need to search for more that
one

yes i search always for the same string(FAX)

> string you need to specify that as well.
> 2. When you create a new Word document what's it's name. Is it's name
derived
> from the original?

the doc's name will have the phone number after FAX

in a word document there's FAX to transmit to different
people with always the same string (FAX:phone number)
so for each number i want to create each word file.

thanks




Re: work with a word doc file by Peter

Peter
Mon Feb 09 00:30:23 CST 2004

Hi isabelle

Each document will only contain 1 fax number? Does the fax number contain
anything other than numbers, spaces, hypens etc? Is the fax number
parenthesised as below or was that just for illustration. What I'm trying
to determine is how do you know when you've reached the end of the fax
number?

Also, if you're using the fax number as the name of the new document what
happens when you send another fax to the same number, since you already
have a file with that name.

You need to clearly state what you're trying to achieve and how you intend
to achieve. I'm not convinced you've thought this through thoroughly.

I'm happy to help with snippets and give you pointers but I don't want to
take on the responsibility of writing a fairly substantial script for you.

As a start here's how you get Word running and do a search. The code
assumes that the fax number starts with the text "Fax:" and the number
consists of Numbers, Spaces, Hyphens:

Option Explicit

Dim wdApp
Dim docNew
Dim rngFaxNo
Dim objArgs
Dim strDocument
Dim strOriginalPrinter

' Get the command line arguments
Set objArgs = WScript.Arguments
If objArgs.Count = 0 Then
MsgBox "You must supply the name of the file to search"
WScript.Quit (1)
Else
strDocument = objArgs.Item(0)
End If


Set wdApp = WScript.CreateObject("Word.Application")
With wdApp.Application

' Open the document specified in the cmd line
Set docNew = .Documents.Open(strDocument)

' Search the document for the fax number
If SearchDoc(docNew, rngFaxNo) Then
MsgBox "Fax number = " & rngFaxNo.Text
Else
MsgBox "Fax number not found"
End If

docNew.Close 0 ' 0 = wdDoNotSaveChanges

.Quit
End With
Set wdApp = Nothing

Function SearchDoc(byval Doc, ByRef Range)
Dim rngReplace
Dim rngFaxNo

Set rngReplace = Doc.Content
With rngReplace.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "Fax:"
.Replacement.Text = ""
.Forward = True
.Wrap = 1 ' wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False

' Find the fax number prefix text
If .Execute Then

' Return the fax number in the Word range object "Range"
Set rngFaxNo = rngReplace
rngFaxNo.Collapse 0 ' wdCollapseEnd
rngFaxNo.MoveEndWhile ("0123456789 -")
set Range = rngFaxNo
SearchDoc = True
End If
End With
End Function

Call the script some thing like:

ScriptName "C:\My Files\Junk.doc"

This will search the Word document C:\My Files\Junk.doc

HTH + Cheers - Peter


"isabelle" <recup60@yahoo.fr> wrote in news:402684a5$0$28153
$636a15ce@news.free.fr:

>
>>
>> Questions:
>>
>> 1. Are you always going to search for the same string, if no please
> provide a
>> sample of what your search string is. Is you need to search for more
that
> one
>
> yes i search always for the same string(FAX)
>
>> string you need to specify that as well.
>> 2. When you create a new Word document what's it's name. Is it's name
> derived
>> from the original?
>
> the doc's name will have the phone number after FAX
>
> in a word document there's FAX to transmit to different
> people with always the same string (FAX:phone number)
> so for each number i want to create each word file.
>
> thanks
>
>
>
>


Re: work with a word doc file by jcochran

jcochran
Mon Feb 09 14:44:31 CST 2004

On Sat, 7 Feb 2004 00:32:13 +0100, "isabelle" <recup60@yahoo.fr>
wrote:

>with my vbs ,
>i want to open a word file and search different
>string in this file when i find this string
>i must create a new word file and put string in this file.
>an idea ??

This would best be handled in VBA, as a Word macro. You can easily
use the Find/Find Next functions to find the string, and
Copy/Open/Paste/Save for the rest. Heck, you can even record the
macro to develop 90% of it.

Jeff