Re: Ping Steve Yandl or other VBScript gurus
- From: "Rhino" <no.offline.contact.please@xxxxxxxxxx>
- Date: Fri, 3 Feb 2006 12:15:33 -0500
"Jean-Guy Marcil" <NoSpam@LeaveMeAlone> wrote in message
news:%23CH575NKGHA.2064@xxxxxxxxxxxxxxxxxxxxxxx
Rhino was telling us:Basically, my statement was inspired by a newsgroup post I found in Google
Rhino nous racontait que :
I realize that this is slightly off-topic for this newsgroup but I've
already posted this question to microsoft.public.scripting.vbscript
and haven't received any replies after almost 24 hours.
Several days ago, Steve Yandl suggested using VBScript when I asked
about a way to launch Word invisibly and then have it execute a
specific macro. He included a sample VBScript that demonstrated the
idea. I've adapted this script to fit my specific situation and it
works wonderfully.
I'm trying to add one small wrinkle to the script and can't figure
out how to do it. The macro that I am launching from the VBScript is
now generating a return code and I need my script to capture that
return code in a variable. At the moment, the return code is a
boolean and will be true if the macro/function works and false if it
doesn't. However, I could change the macro/function to return a long
if that is easier in any way. By the way, I'm assuming that VBA and
VBScript follow the convention that False and 0 are synonymous, as
are True and 1; please correct me if I'm wrong about that!
Here's my script:
============================================================
' Get arguments into variables
If WScript.Arguments.Count > 0 Then
MsgBox "Too many arguments; expecting none."
WScript.Quit
End If
' Find path for MyDocuments folder
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(&H5&)
strMyDocPath = objFolder.Self.Path
' Start Word Application, open resume.doc in MyDocuments
Set oWd = CreateObject("Word.Application")
oWd.Visible = False
Set oDoc = oWd.Documents.Open(strMyDocPath & "\resume.doc")
'Run macro named createResumeFromFile, which has no arguments, and
catch its return code
dim bWaitOnReturn
bWaitOnReturn=True
retcde=oWd.run("createResumeFromFile",,bWaitOnReturn)
'oWd.Run "createResumeFromFile"
'Save changes to doc on closing and quit Word
oDoc.Save
oDoc.Close
oWd.Quit
Set oWd = Nothing
Set objShell = Nothing
'Exit the script with the value of the return code from the
macro/function wscript.quit(retcde)
============================================================
When I execute this script, I get the following error on line (21,
1), which is the 'retcde=oWd.run' line:
Microsoft VBScript runtime error: Wrong number of arguments or invalid
property assignment
Can anyone tell me what I'm doing wrong?
I thought that the problem might be that I didn't 'dim' retcde but
adding a 'dim retcde' didn't help. I thought that the problem might
be that 'dim bWaitOnReturn' didn't define the variable as Boolean but
adding 'as Boolean' caused a syntax error. So I'm guessing that I've
constructed the 'run' statement incorrectly but don't know where to
find documentation on the correct formulation of the statement.
I really don't want to take a couple of days to develop a working
knowledge of VBScript at this point; I've already spent a few days
getting a working knowledge of VBA so that I could write my macros. I
really need to get this script working so that I can move on to
other things.
Can anyone enlighten me on how to fix my script?
It seems to me that you have one comma too many:
retcde=oWd.run("createResumeFromFile",,bWaitOnReturn)
should be
retcde=oWd.run("createResumeFromFile",bWaitOnReturn)
No?
which was attempting to solve the same problem; the proposed solution in
that post showed two commas between the two parameters so that's what I did
in my statement. But I don't have a VBScript reference manual so I was
working blind: I couldn't check that syntax to be sure it was valid - and I
still can't unless someone can point me to a VBScript reference.
That won't be necessary now; I've solved the problem. See my reply to Steve
Show us the "createResumeFromFile" Sub declaration line.
Yandl elsewhere in this thread. Apparently, I didn't need any parameters for
the Run command beyond the macro name: that's what was causing my errors.
--
Salut!
Et vous aussi! Merci pour votre aide!
--
Rhino
.
- References:
- Ping Steve Yandl or other VBScript gurus
- From: Rhino
- Re: Ping Steve Yandl or other VBScript gurus
- From: Jean-Guy Marcil
- Ping Steve Yandl or other VBScript gurus
- Prev by Date: Re: Ping Steve Yandl or other VBScript gurus
- Next by Date: Re: Word shld let me increase whole doc's font size by same increment
- Previous by thread: Re: Ping Steve Yandl or other VBScript gurus
- Next by thread: How to remove a template that keeps coming back after being removed?
- Index(es):
Relevant Pages
|
Loading