Outlook Macros Part 1

January 5, 2010

Keeping in mind my New Year’s resolution to blog about my projects, and their progress, I present to you my investigations into Outlook macros. If you weren’t aware of it, Outlook lets you write scripts, or macros, in Visual Basic that allow you to automate repetitive tasks. There are a few things I’d like to automate but I’ll start with this:

I send out a lot of form emails at work but there only a few templates that I use, and the only things different in each message are the names and account information.  I’d like to have Outlook prompt me for account information and template choice, and then generate the email for me to review and send.

I did a bit of Googling and found Microsoft Outlook 2007 Programming. I went to Safari books, a very neat online library service I use, checked it out and began reading. Then I noticed I had Outlook 2003, not 2007. There is a book for that by the same author, but not at Safari. I’d have to buy it. I’ll stick with what I can get online for now.

I couldn’t find any online tutorials, just stuff for writing executable applications. I don’t need to go that far. I looked at the Microsoft documentation but I always have a hard time parsing that kind of stuff. It’s something I know I need to improve on, but I’d much rather find something easy to understand so I can actually get some programming done instead of pouring over class definitions and function descriptions for hours or days before I actually get to what I want.

I couldn’t find anything else so I decided to see what I could do with the book on Outlook 2007. With the first “hello world” example I got weird error saying macros weren’t allowed in this session or some such silliness. After more googling I discovered I might be able to solve the problem by creating my own developer certificate. I fiddled around with them but didn’t finish and called it a day.

Later I opened outlook and tried to run the macro again. It asked me if I should allow macros and I said yes. The program generated an email for me with “Hello World” as the subject line. Hooray! First success! Here’s the code. With some slight editorial changes. :P

Public Sub helloDorks()
Dim msg As Outlook.MailItem
Set msg = Application.CreateItem(olMailItem)
msg.Subject = “Space Station”
msg.Body = “What’s the progress on warp drive? When will it be online? My gerbils are getting tired and I’m running out of carrots.”
msg.Display
Set msg = Nothing
End Sub

Actually I think this is very close to what I want. I can change the subject line and body to say what I like. Now I just need to figure out how to prompt for user input and I think I’m in business.

Advertisement

One Response to “Outlook Macros Part 1”


  1. [...] 6, 2010 In Outlook Macros Part 1 I managed to use a macro that generated an email with a specified subject and body. Now it’s [...]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.