Passing variables from Outlook to a Word Macro

B

brotherescott

I am trying to send a argument along with a macro call from Outlook
2003 SP1 to Word 2003. The macro call works but I can not get the
argument/variable to work. I think I followed the syntax in the Word
help file,under Run Method, but I still get a "run-time error 438"
message.


'Outlook VBA to start up word and load the correct template
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = True
If WordApp Is Nothing Then
MsgBox "Couldn't Start Word . . . ."
Else
Set oDoc = WordApp.Documents.Add("C:\Documents and


Settings\riddlesm\Application Data\Microsoft\Templates\Pella\Meeting
DateVB3.dot")
End If

If WordApp.ActiveWindow.View.SplitSpecial <> wdPaneNone Then
WordApp.ActiveWindow.Panes(2).Close
End If
If WordApp.ActiveWindow.ActivePane.View.Type = wdNormalView Or
WordApp.ActiveWindow.ActivePane.View.Type = wdOutlineView Then
WordApp.ActiveWindow.ActivePane.View.Type = wdPrintView
End If


WordApp.ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageHeader


A="test" 'variable I am trying to send
WordApp.Run Macroname:="'C:\Documents and


Settings\riddlesm\Application Data\Microsoft\Templates\Pella\Meeting
DateVB3.dot' !macro2", varg1:=A

'The Above Oulook code is the one that generates the error. I
'believe that it is in the correct format but maybe I am
'not seeing something.


Here is my word macro that it calls:
Sub Macro2(A As String)
MsgBox A
End Sub
 
J

Jonathan West

Hi brotherscott


WordApp.Run Macroname:="'C:\Documents and


Settings\riddlesm\Application Data\Microsoft\Templates\Pella\Meeting
DateVB3.dot' !macro2", varg1:=A

'The Above Oulook code is the one that generates the error. I
'believe that it is in the correct format but maybe I am
'not seeing something.


there\are a few problems with the syntax here.

You don't need to include the template name if the template is loaded
(either as the template attached to the current document or loaded as an
add-in) and the macro name is unique. It won't run at all if the template
isn't currently loaded. You also need to get rid of the single quotes, and
replace the exclamation mark with a quote. If the template is loaded, then
this should work



WordApp.Run Macroname:="macro2", varg1:=A
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top