Re: Passing variable to MS Word Macro
Re: Passing variable to MS Word Macro
- Subject: Re: Passing variable to MS Word Macro
- From: David Wignall <email@hidden>
- Date: Wed, 26 Feb 2003 21:49:54 +1300
on 26/2/2003 9:24 AM, Steve Suranie at email@hidden wrote:
>
I'm trying to pass the value of a variable to a MS Word Macro. I can send a
>
string but not a variable:
>
>
tell application "Microsoft Word"
>
activate
>
do Visual Basic "dnwMSWMacro \"Hello, World!\""
>
end tell
>
>
Here's the macro:
>
>
Sub dnwMSWMacro(thisMessage)
>
'
>
' dnwMSWMacro Macro
>
' Macro recorded 2/25/03 by Advance News Magazines
>
'
>
MsgBox thisMessage
>
End Sub
>
>
But when I go to do something like this:
>
>
set magName to "Advance for Audiologists"
>
tell application "Microsoft Word"
>
activate
>
do Visual Basic "dnwMSWMacro magName
>
end tell
>
>
it bombs.
The do Visual basic passes a string to VBA, so what was happening in your
second example is that it was treating magName as a value rather than a
variable. Instead, you need to set the value of the variable in VBA. Also
bear in mind that Word creates a temporary procedure, Sub TmpDDE(), inside
of which it wraps the string sent by AppleScript. So, this works
tell application "Microsoft Word"
activate
do Visual Basic "dim str as string
str = \"Advance for Audiologists\"
dnwMSWMacro str"
end tell
Those are line breaks inside the do Visual Basic string. Word compiles the
temporary procedure that sets the value of the variable str and then calls
dnwMSWMacro with str as the argument
>
Thanks
Sure, hope it helps :)
--
Dave
"Perhaps the truth is less interesting than the facts?"
Amy Weiss,
The RIAA's Senior Vice President of Communications
Email to The Register
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.