Hi,
I'm trying to write a VB script that will search & replace stuff in a Word doc. The entire script is between the dashed lines:
------------------------------------------
Dim args
Dim num
Set args = WScript.Arguments
num = args.Count
If num < 3 Then
WScript.Echo "Usage: Replacer.vbs <filename> [<tag> <value> ... ]"
WScript.Quit 1
End If
Dim i
Dim myWord
Set myWord = CreateObject("Word.Application"
With myWord
.Documents.Open args(0), , False
.Visible = True
With .Selection.Find
For i = 1 To num - 1 Step 2
.text = args(i)
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.text = args(i + 1)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
Next
End With
.Documents(1).Save
'.Quit 0
End With
------------------------------------------
Unfortunately I get "Expected Statement" Error at Line 33 Char 30, which is (marked in red):
.Execute Replace:=wdReplaceAll
I have tried different things like:
.Execute args(i), True, False, False, False, True, True, False, args(i+1), wdReplaceAll
All to no avail.
Any help appreciated,
Complete Newbie.
I'm trying to write a VB script that will search & replace stuff in a Word doc. The entire script is between the dashed lines:
------------------------------------------
Dim args
Dim num
Set args = WScript.Arguments
num = args.Count
If num < 3 Then
WScript.Echo "Usage: Replacer.vbs <filename> [<tag> <value> ... ]"
WScript.Quit 1
End If
Dim i
Dim myWord
Set myWord = CreateObject("Word.Application"
With myWord
.Documents.Open args(0), , False
.Visible = True
With .Selection.Find
For i = 1 To num - 1 Step 2
.text = args(i)
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.text = args(i + 1)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
Next
End With
.Documents(1).Save
'.Quit 0
End With
------------------------------------------
Unfortunately I get "Expected Statement" Error at Line 33 Char 30, which is (marked in red):
.Execute Replace:=wdReplaceAll
I have tried different things like:
.Execute args(i), True, False, False, False, True, True, False, args(i+1), wdReplaceAll
All to no avail.
Any help appreciated,
Complete Newbie.