Re: Q: Passing values to VBA macros (Word 98)
Re: Q: Passing values to VBA macros (Word 98)
- Subject: Re: Q: Passing values to VBA macros (Word 98)
- From: Paul Berkowitz <email@hidden>
- Date: Wed, 14 Feb 2001 12:58:18 -0800
On 2/14/01 11:47 AM, "Frank Watzl" <email@hidden> wrote:
>
Runner's msgBox is displayed properly. Now, I want to pass a string to the
>
VBA subroutine named "Passer(theParam)". This doesn't work :-(
>
>
tell application "Word"
>
do script "Passer(\"Applescript did this call\")"
>
end tell
>
>
What I get is a VBA Code window opening, displaying
>
>
Sub TmpDDE()
>
>
Passer__ ("Applescript did this")
>
End Sub
>
>
accompanies by a dialog saying "Sub or Function not defined".
>
>
How can I successfully pass Parameters to a VBA sub?
>
If you go to Tools-->Macro-->Macros in your front document, you'll see that
the other two subs show up as macros, but Passer doesn't. Without a full
definition, it exists only as an interior Sub of one of the other macros. So
it's not an script that can be called on its own. There is more than one way
to do what you want here.
You could forget about the saved Subs and do this:
tell application "Microsoft Word" -- change to "Word" for yourself
activate
do Visual Basic "Dim theParam As String
theParam = \"Applescript did this call\"
MsgBox(theParam)"
end tell
[or simply]
tell application "Microsoft Word"
activate
do Visual Basic "MsgBox(\"Applescript did this call\")"
end tell
That works fine. If you really want to set it up within a Macro, then set up
a Sub like caller:
Sub appler()
Call passer("AppleScript did this call")
End Sub
Then
tell application "Microsoft Word"
activate
do script "appler()"
end tell
That works too. There is also probably a way to pass a value to a VB
variable in a VB Macro, but I'm sure you'd have to call a self-standing
macro that contains an interior sub, and you may need to do it via do Visual
basic and not do script. i have successfully passed As variables to do
Visual basic before:
set theParam to "AppleScript did this call"
tell application "Microsoft Word"
activate
do Visual Basic "MsgBox(\"" & theParam & "\")"
end tell
This also works. Will it do for your purposes?
--
Paul Berkowitz