Given an Outlook mail item is opened (active), I would like to use MS script to call a macro named Normal.AS_Marcos.Email_Style. It fails.
Please show me a proper way to call an Outlook macro from MS script.
Thanks.
VBSTART
Sub Email_Style()
set app=createobject("Outlook.Application")
app.run MacroName:=Normal.AS_Macros.Email_Style
End Sub
VBEND
VBScript Calls a Macro in Outlook
Moderators: JRL, Dorian (MJT support)
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Looks like it should be:
Code: Select all
VBSTART
Sub Email_Style()
set app=createobject("Outlook.Application")
app.run "Normal.AS_Macros.Email_Style"
End Sub
VBEND
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Marcus,
The following is the Outlook/Word macro in question:
Sub Email_Style()
ActiveWindow.View.Type = wdWebView
WordBasic.MailAsHTML
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = "C:\ArmSys\Word\Template\Email.dot"
.XMLSchemaReferences.AutomaticValidation = True
.XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
End With
Selection.Style = ActiveDocument.Styles("Email Normal")
End Sub
The VBA macro runs successfully to apply changes to an active Outlook mail item.
The following is the Outlook/Word macro in question:
Sub Email_Style()
ActiveWindow.View.Type = wdWebView
WordBasic.MailAsHTML
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = "C:\ArmSys\Word\Template\Email.dot"
.XMLSchemaReferences.AutomaticValidation = True
.XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
End With
Selection.Style = ActiveDocument.Styles("Email Normal")
End Sub
The VBA macro runs successfully to apply changes to an active Outlook mail item.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
To be honest I have no experience of writing VBA in Outlook, so I'm not familiar with what properties and methods are available. It would seem that Outlook does not offer a Run command for running macros in the same way that Word does.
Also - I guess you need to have Outlook open and an item active for your macro to work? But your code creates a new Outlook instance and then tries to run the macro. Presumably the item won't be active if Outlook has just been started.
So you'd probably need to split your code up, have a function that does the CreateObject to open Outlook and then another to select and activate the item. Then your code above. Either by finding a way to run Outlook macros (I'll search the docs and see what I can find), or converting that code to VBScript.
Also - I guess you need to have Outlook open and an item active for your macro to work? But your code creates a new Outlook instance and then tries to run the macro. Presumably the item won't be active if Outlook has just been started.
So you'd probably need to split your code up, have a function that does the CreateObject to open Outlook and then another to select and activate the item. Then your code above. Either by finding a way to run Outlook macros (I'll search the docs and see what I can find), or converting that code to VBScript.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
All I could find for running VBA macros from outside of Outlook was this:
http://groups.google.com/group/microsof ... 2adbfbb537
But I couldn't get it to work. Sorry.
http://groups.google.com/group/microsof ... 2adbfbb537
But I couldn't get it to work. Sorry.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Marcus,
This shows the strength and beauty of Macro Scheduler--short learning curve and fast result.
My workaround solution is pure MS code:
SRT>VBA_Email_Style
Press ALT
Press F8
Release ALT
WaitWindowOpen>Macros
Wait>.1
Send>Email_Style
Wait>.1
Press ALT
Send>r
Release ALT
End>VBA_Email_Style
Most importantly, it works fine.
Thanks for your help.
This shows the strength and beauty of Macro Scheduler--short learning curve and fast result.
My workaround solution is pure MS code:
SRT>VBA_Email_Style
Press ALT
Press F8
Release ALT
WaitWindowOpen>Macros
Wait>.1
Send>Email_Style
Wait>.1
Press ALT
Send>r
Release ALT
End>VBA_Email_Style
Most importantly, it works fine.
Thanks for your help.