Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - New to VBscript, Help please!

Reply
 
Old 06-17-2009   #1 (permalink)
yu


 
 

New to VBscript, Help please!

Dear All,

It is my first time to write a Vb script to automate Word document
processing. What I am trying to accompish is to find a specific
keyword, then Bold it. the keyword will be appearing many times in the
WORD document. here is what I have tried. the script is runing with
error. but no change was made to document.
can someone kindly point out what is wrong?

Thank you!

Yu

------------------------test.vbs--------------------------------

Set ObjWord = createobject("Word.Application")
Set ObjWdDoc = ObjWord.Documents.Open(FileName:="c:\test.doc")
ObjWord.Visible = True
Set ObjWdRange = ObjWdDoc.Content
With ObjWdRange.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "Randomized ID:"
.MatchCase = True
With .Replacement.Font
.Bold = True
End With
.Execute wdReplaceAll
End With


My System SpecsSystem Spec
Old 06-17-2009   #2 (permalink)
Joe Fawcett


 
 

Re: New to VBscript, Help please!

That code is VBA, not VBScript. VBScript does not support named arguments
(e.g. FileName :=)
You will also need to define the constants such as wdReplaceAll.

--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name
"yu" <zhangyu05@xxxxxx> wrote in message
news:788627e9-c322-48f6-b216-b6bcf813dd7b@xxxxxx
Quote:

> Dear All,
>
> It is my first time to write a Vb script to automate Word document
> processing. What I am trying to accompish is to find a specific
> keyword, then Bold it. the keyword will be appearing many times in the
> WORD document. here is what I have tried. the script is runing with
> error. but no change was made to document.
> can someone kindly point out what is wrong?
>
> Thank you!
>
> Yu
>
> ------------------------test.vbs--------------------------------
>
> Set ObjWord = createobject("Word.Application")
> Set ObjWdDoc = ObjWord.Documents.Open(FileName:="c:\test.doc")
> ObjWord.Visible = True
> Set ObjWdRange = ObjWdDoc.Content
> With ObjWdRange.Find
> .ClearFormatting
> .Replacement.ClearFormatting
> .Text = "Randomized ID:"
> .MatchCase = True
> With .Replacement.Font
> .Bold = True
> End With
> .Execute wdReplaceAll
> End With
>


My System SpecsSystem Spec
Old 06-17-2009   #3 (permalink)
Joe Fawcett


 
 

Re: New to VBscript, Help please!

Removing the ability to supply named arguments often means you need to put
in all the parameters, this worked for me:

Public Const wdReplaceAll = 2
Public Const wdFindContinue = 1
Set ObjWord = createobject("Word.Application")
Set ObjWdDoc = ObjWord.Documents.Open("C:\test.doc")
ObjWord.Visible = True
Dim rng
Set rng = ObjWdDoc.Content
With rng.Find
.Replacement.ClearFormatting
.Replacement.Font.Bold = True
.Execute "Randomized ID:", False, False, False, False, False, True,
wdFindContinue, True, "Randomized ID:", wdReplaceAll
End With

--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name


"Joe Fawcett" <joefawcett@xxxxxx> wrote in message
news:#xK$Vey7JHA.1416@xxxxxx
Quote:

> That code is VBA, not VBScript. VBScript does not support named arguments
> (e.g. FileName :=)
> You will also need to define the constants such as wdReplaceAll.
>
> --
>
> Joe Fawcett (MVP - XML)
> http://joe.fawcett.name
> "yu" <zhangyu05@xxxxxx> wrote in message
> news:788627e9-c322-48f6-b216-b6bcf813dd7b@xxxxxx
Quote:

>> Dear All,
>>
>> It is my first time to write a Vb script to automate Word document
>> processing. What I am trying to accompish is to find a specific
>> keyword, then Bold it. the keyword will be appearing many times in the
>> WORD document. here is what I have tried. the script is runing with
>> error. but no change was made to document.
>> can someone kindly point out what is wrong?
>>
>> Thank you!
>>
>> Yu
>>
>> ------------------------test.vbs--------------------------------
>>
>> Set ObjWord = createobject("Word.Application")
>> Set ObjWdDoc = ObjWord.Documents.Open(FileName:="c:\test.doc")
>> ObjWord.Visible = True
>> Set ObjWdRange = ObjWdDoc.Content
>> With ObjWdRange.Find
>> .ClearFormatting
>> .Replacement.ClearFormatting
>> .Text = "Randomized ID:"
>> .MatchCase = True
>> With .Replacement.Font
>> .Bold = True
>> End With
>> .Execute wdReplaceAll
>> End With
>>
>
>
>


My System SpecsSystem Spec
Old 06-17-2009   #4 (permalink)
yu


 
 

Re: New to VBscript, Help please!

On Jun 17, 4:32*am, "Joe Fawcett" <joefawc...@xxxxxx> wrote:
Quote:

> Removing the ability to supply named arguments often means you need to put
> in all the parameters, this worked for me:
>
> Public Const wdReplaceAll = 2
> Public Const wdFindContinue = 1
> Set ObjWord = createobject("Word.Application")
> Set ObjWdDoc = ObjWord.Documents.Open("C:\test.doc")
> ObjWord.Visible = True
> Dim rng
> Set rng = ObjWdDoc.Content
> With rng.Find
> * .Replacement.ClearFormatting
> * .Replacement.Font.Bold = True
> * .Execute "Randomized ID:", False, False, False, False, False, True,
> wdFindContinue, True, "Randomized ID:", wdReplaceAll
> End With
>
> --
>
> Joe Fawcett (MVP - XML)http://joe.fawcett.name
>
> "Joe Fawcett" <joefawc...@xxxxxx> wrote in message
>
> news:#xK$Vey7JHA.1416@xxxxxx
>
Quote:

> > That code is VBA, not VBScript. VBScript does not support named arguments
> > (e.g. FileName :=)
> > You will also need to define the constants such as wdReplaceAll.
>
Quote:

> > --
>
Quote:

> > Joe Fawcett (MVP - XML)
> >http://joe.fawcett.name
> > "yu" <zhangy...@xxxxxx> wrote in message
> >news:788627e9-c322-48f6-b216-b6bcf813dd7b@xxxxxx
Quote:

> >> Dear All,
>
Quote:
Quote:

> >> It is my first time to write a Vb script to automate Word document
> >> processing. What I am trying to accompish is to find a specific
> >> keyword, then Bold it. the keyword will be appearing many times in the
> >> WORD document. here is what I have tried. the script is runing with
> >> error. but no change was made to document.
> >> can someone kindly point out what is wrong?
>
Quote:
Quote:

> >> Thank you!
>
Quote:
Quote:

> >> Yu
>
Quote:
Quote:

> >> ------------------------test.vbs--------------------------------
>
Quote:
Quote:

> >> Set ObjWord = createobject("Word.Application")
> >> Set ObjWdDoc = ObjWord.Documents.Open(FileName:="c:\test.doc")
> >> *ObjWord.Visible = True
> >> Set ObjWdRange = ObjWdDoc.Content
> >> * * With ObjWdRange.Find
> >> * * * * * .ClearFormatting
> >> * * * * * .Replacement.ClearFormatting
> >> * * * * * .Text = "Randomized ID:"
> >> * * * * * .MatchCase = True
> >> * * * * With .Replacement.Font
> >> * * * * * .Bold = True
> >> * * * * End With
> >> * * * * * .Execute wdReplaceAll
> >> * * End With
Joe,

thank you so much.I will try the code later.

Yu
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
CSS and VBscript VB Script
Where is VBscript now? VB Script
VBscript Help VB Script
How to do No hang up VBScript (nohup for VBScript) VB Script
vbscript and HTA help VB Script


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46