Insert Words Macro in Outlook

L

Lee Brown

I am having problems with creating a macro in Outlook.
Before sending my emails off I have 3 different items
that need to be included in my email (these items change
periodically). I am still learning how to program in
visual basic so my knowledge is limited. My program in
Word looks like this:

Selection.TypeText Text:="60th EMS" & vbCrLf
Selection.TypeText Text:="lb" & vbCrLf
Selection.TypeText Text:="9535" & vbCrLf

I wanted to have the same macro in Outlook but I am
having problems, I started out with this:

Dim MyApp As Application
Dim MyObj As Object

Set MyApp = CreateObject("Outlook.Application")

But to tell you the truth I am not really sure how to
proceed could someone please help me?

Thanks in Advance,
Lee Brown
 
E

Eric Legault [MVP - Outlook]

You could wire this macro in Outlook to a custom toolbar button and click it
before you send the message:

Sub InsertTextInCurrentMessage()
Dim objCurrentMessage As Outlook.MailItem

If ActiveInspector.CurrentItem.Class <> olMail Then Exit Sub
Set objCurrentMessage = ActiveInspector.CurrentItem

objCurrentMessage.Body = objCurrentMessage.Body & vbCrLf & "60th EMS" &
vbCrLf & "lb" & vbCrLf & "9535" & vbCrLf

End Sub

Note that when working with macros in Outlook, the Outlook.Application
object is always available just by calling the Application object; you don't
have to declare a variable for it. Same goes for ActiveInspector,
ActiveExplorer, etc. Chech the <globals> section in the Object Browser to
see the others.
 

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