Insert Words Macro in Outlook

  • Thread starter Thread starter Lee Brown
  • Start date Start date
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
 
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.
 
Back
Top