Re: Ping Steve Yandl or other VBScript gurus




"Jean-Guy Marcil" <NoSpam@LeaveMeAlone> wrote in message
news:%23CH575NKGHA.2064@xxxxxxxxxxxxxxxxxxxxxxx
Rhino was telling us:
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?

Basically, my statement was inspired by a newsgroup post I found in Google
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.


Show us the "createResumeFromFile" Sub declaration line.

That won't be necessary now; I've solved the problem. See my reply to Steve
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


.



Relevant Pages

  • Re: Ping Steve Yandl or other VBScript gurus
    ... post on the vbscript newsgroup and that got me going in the right direction. ... 'Run macro named createResumeFromFile, which has no arguments, and catch its ... 'Exit the script with the value of the return code from the macro/function. ... how to do what I want to do entirely in VBA or VBScript; ...
    (microsoft.public.word.vba.general)
  • Re: Ping Steve Yandl or other VBScript gurus
    ... In vbScript, all variables are variants. ... I've not seen your VBA code but generally you're better of going entirely ... Use of vbs to run a macro in Word can be ... I'm trying to add one small wrinkle to the script and can't figure out how ...
    (microsoft.public.word.vba.general)
  • Re: Automatically enable the macros when a excel file is opened
    ... VBScript might be able to help you. ... the macro can be transfered to a script which automates Excel and is ... Alternatively - a script can sidestep ... I'll hedge and say that I have not launched Excel ...
    (microsoft.public.excel.programming)
  • Re: Ping Steve Yandl or other VBScript gurus
    ... Steve Yandl suggested using VBScript when I asked ... I'm trying to add one small wrinkle to the script and can't figure ... The macro that I am launching from the VBScript is ... be that 'dim bWaitOnReturn' didn't define the variable as Boolean but ...
    (microsoft.public.word.vba.general)
  • Re: LDAP query information
    ... execution of the vbscript? ... The error message indicates the line number in the script, ... Dim strBase, strFilter, strAttributes, strQuery, adoRecordset ... ' Construct LDAP syntax query. ...
    (microsoft.public.windows.server.scripting)

Loading