Creating a macro in Outlook

R

rmccafferty

I had a macro in Outlook XP that entered a certain amount of text and
formatted it. We use it in most of our emails and immediately run it when
creating a new email. It worked fine. (For what it is worth, I copied it
into a Word 2007 macro and it worked fine there also).

I cannot figure out to create this macro in Outlook 2007. I went to trust
center and enabled all macros with no security at all.

I went to Tools, Macros, Visual Basic Editor. In the top left box I created
a new module and pasted in the text of the macro. But now I cannot figure
out how to run it in a new email. In a newly created macro there is no tool
option to call up a macro.

I try to run it within the visual basic editor, but I get an error message
that says macros in this project are disabled and refers me to online help
for how to enable macros.

How do I create a macro that I can run upon opening a new email that is to
be sent?

If it matters at all, the text in the macro is:
Sub EmailProtocol()
'
' EmailProtocol Macro
' Macro recorded 8/22/2006 by Gisele Prive
'
Selection.InsertDateTime DateTimeFormat:="d-MMM-yy",
InsertAsField:=False, _
DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
Selection.TypeText Text:=" "
Selection.InsertDateTime DateTimeFormat:="HH:mm", InsertAsField:=False, _
DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
Selection.TypeText Text:=" PST "
Selection.MoveLeft Unit:=wdCharacter, Count:=2
Selection.MoveLeft Unit:=wdCharacter, Count:=9, Extend:=wdExtend
Selection.Font.Bold = wdToggle
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:="-- Folder"
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="Message Subject > "
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.MoveRight Unit:=wdWord, Count:=2
End Sub
 
K

Ken Slovak - [MVP - Outlook]

You can add a macro call command to the QAT in an Outlook email. Each type
of Outlook item has its own ribbon and QAT, so if you want the macro call in
the QAT for both reading emails and composing them you'd need to add it to
both QAT's.

Right-click on the ribbon and select Customize Quick Access Toolbar. Select
Macros in the choose commands from drop-down. Select your macro.

You can also put code in the ThisOutlookSession class module that's
instantiated in Application_Startup() that instantiates an Inspectors
collection declared WithEvents that's used to handle the NewInspector()
event. In that event you instantiate an Inspector object declared WithEvents
to the new Inspector. Then in the first Inspector.Activate() event you can
call to your macro code.

Note that your code will work only if the full Word 2007 is also installed.
Also, there is a behavior change in Outlook 2007 where the item in the
Inspector in NewInspector() is not fully populated with properties until the
first Inspector.Activate() event. Until then it's a weak object reference.
 

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