views:

128

answers:

1

I have been going mad trying to figure out why my scripts weren't working, until I started copying and pasting sample source code directly from a few websites only to have it fail there as well. I am getting the following error in my VBScripts:

C:\temp\vbs\script.vbs(19, 53) Microsoft VBScript compilation error: Expected statement'

For a line of code that looks like this:

    wdoc.Application.Selection.Find.Execute Replace:=wdReplaceAll

This is interfacing with Microsft Word in Office 2007 to conduct a search and replace. Index 53 point directly to the := part of the assignment. Since this type of syntax doesn't work on my machine and I am using it from several websites, I was wondering if the cscript.exe I use is out of date.

Am I not calling cscript properly?

+4  A: 

Named arguments (Param:=Value) are Visual Basic and VBA feature; this syntax isn't supported in VBScript.

In VBScript, you need to preserve the actual order of a routine's arguments. If a specific argument is optional and you want to use its default value, you need to simply omit that argument. So, your code should look like this:

Const wdReplaceAll = 2
wdoc.Application.Selection.Find.Execute , , , , , , , , , , wdReplaceAll
Helen
Awesome, thanks. I mean... that's not awesome: that really sucks and is horrendous syntax, but I guess I gotta do what I gotta do. Thanks for providing the right answer.
IcedDante
@IcedDante: you can accept Helen's answer by clicking the checkmark next to it.
Otaku