find/replace in a Word Doc using word object and vbscript 
Author Message
 find/replace in a Word Doc using word object and vbscript

Help to anyone,

i have this code:

Dim WordDoc

   Set WordDoc = CreateObject("Word.Application")
   WordDoc.Visible = True
   WordDoc.Documents.Open "c:\generic.doc", ConfirmConversions = True,
ReadOnly = False

i have criteria to select certain words and then change the words, i find
the words ok, but the script does nothing when i try to write to the word
doc.  it appears to be read-only, even though i am trying to open as
read/write.

is this readonly inherent to the Documents.Open?

David Frank



Sun, 08 Jun 2003 04:57:34 GMT  
 find/replace in a Word Doc using word object and vbscript
WordDoc.Documents.Open "c:\generic.doc", ConfirmConversions = True, ReadOnly
= False

is (almost) VBA syntax for named arguments (ReadOnly := False would be
correct VBA syntax).

In any case, VBScript does not support named argument syntax.  You have to
code everything as the correct positional argument.

object.method arg1,,arg3,,,,,,,arg10

Look up the methods correct positional syntax in the Word Visual Basic
documentation - it can get pretty ugly ;-)...

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--


Quote:
> Help to anyone,

> i have this code:

> Dim WordDoc

>    Set WordDoc = CreateObject("Word.Application")
>    WordDoc.Visible = True
>    WordDoc.Documents.Open "c:\generic.doc", ConfirmConversions = True,
> ReadOnly = False

> i have criteria to select certain words and then change the words, i find
> the words ok, but the script does nothing when i try to write to the word
> doc.  it appears to be read-only, even though i am trying to open as
> read/write.

> is this readonly inherent to the Documents.Open?

> David Frank



Sun, 08 Jun 2003 11:30:09 GMT  
 find/replace in a Word Doc using word object and vbscript
thanks, Michael.  with the positional arguments, do i not even use 'ReadOnly
= False'?  would i just comma over to the 3rd argument and type'False'?

please advise

df


Quote:
> WordDoc.Documents.Open "c:\generic.doc", ConfirmConversions = True,
ReadOnly
> = False

> is (almost) VBA syntax for named arguments (ReadOnly := False would be
> correct VBA syntax).

> In any case, VBScript does not support named argument syntax.  You have to
> code everything as the correct positional argument.

> object.method arg1,,arg3,,,,,,,arg10

> Look up the methods correct positional syntax in the Word Visual Basic
> documentation - it can get pretty ugly ;-)...

> --
> Michael Harris
> Microsoft.MVP.Scripting
> --

> Please do not email questions - post them to the newsgroup instead.
> --



> > Help to anyone,

> > i have this code:

> > Dim WordDoc

> >    Set WordDoc = CreateObject("Word.Application")
> >    WordDoc.Visible = True
> >    WordDoc.Documents.Open "c:\generic.doc", ConfirmConversions = True,
> > ReadOnly = False

> > i have criteria to select certain words and then change the words, i
find
> > the words ok, but the script does nothing when i try to write to the
word
> > doc.  it appears to be read-only, even though i am trying to open as
> > read/write.

> > is this readonly inherent to the Documents.Open?

> > David Frank



Sun, 08 Jun 2003 12:29:18 GMT  
 find/replace in a Word Doc using word object and vbscript
That's correct, just use variable names that contain the correct value,
literals (string or numeric depending on what's needed), or named constants
(like True/False), all in the right position.  You can skip any optional arg
where the default value is OK...

obj.method arg1varname,,"arg 3 literal",4,True,,,False

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--


Quote:
> thanks, Michael.  with the positional arguments, do i not even use
'ReadOnly
> = False'?  would i just comma over to the 3rd argument and type'False'?

> please advise

> df



> > WordDoc.Documents.Open "c:\generic.doc", ConfirmConversions = True,
> ReadOnly
> > = False

> > is (almost) VBA syntax for named arguments (ReadOnly := False would be
> > correct VBA syntax).

> > In any case, VBScript does not support named argument syntax.  You have
to
> > code everything as the correct positional argument.

> > object.method arg1,,arg3,,,,,,,arg10

> > Look up the methods correct positional syntax in the Word Visual Basic
> > documentation - it can get pretty ugly ;-)...

> > --
> > Michael Harris
> > Microsoft.MVP.Scripting
> > --

> > Please do not email questions - post them to the newsgroup instead.
> > --



> > > Help to anyone,

> > > i have this code:

> > > Dim WordDoc

> > >    Set WordDoc = CreateObject("Word.Application")
> > >    WordDoc.Visible = True
> > >    WordDoc.Documents.Open "c:\generic.doc", ConfirmConversions = True,
> > > ReadOnly = False

> > > i have criteria to select certain words and then change the words, i
> find
> > > the words ok, but the script does nothing when i try to write to the
> word
> > > doc.  it appears to be read-only, even though i am trying to open as
> > > read/write.

> > > is this readonly inherent to the Documents.Open?

> > > David Frank



Sun, 08 Jun 2003 13:25:49 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Find and Replace in Word Doc

2. Finding Word 6.0/95 files and replacing them in Word 2000 format

3. Finding text inside Word doc without Word?

4. Find multiple words Using MS Word Find

5. help merging data file with word doc using vbscript

6. replacing text in word 97 using vbscript

7. Find and Replace in Word Document using VBA

8. VB.Net using a Word doc object - copying in text w/ a hard return

9. Using Word Object to merge doc from VB

10. Replacing Header Text in word doc with VB

11. replace picture in Word doc header?

12. Q:Replace inline shape with text in word doc

 

 
Powered by phpBB® Forum Software