Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

Passing variables from Outlook to a Word Macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
brotherescott@yahoo.com - 28 Dec 2004 14:12 GMT
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
Jonathan West - 28 Dec 2004 14:42 GMT
Hi brotherscott

> WordApp.Run Macroname:="'C:\Documents and
>
[quoted text clipped - 4 lines]
> '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

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup


Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.