Outlook Macros Part 3
January 15, 2010
This is part 3 of my adventure in outlook programming. If you didn’t know, you can write pretty sophisticated macros to automate tasks in outlook. Just go to tools->macros->visual-basic-editor and start coding.
In Outlook Macros Part 2 I had gotten as far as making a form (with buttons and text boxes and such) and was stumped by the drop down menu. I want a drop down menu with 3 choices. I did a little googling and it looks like I can add the choices in the code. I decided to set that part aside for now.
It took some time to figure out how to launch the form I had made but I finally found it.
UserForm1.Show
UserForm1 is just a place name. My form has a different name. I’m hesitant to show the actual code I’ve written because it’s job related. I think what I’ll do is make another dummy form and show you the code for that. By the way, make sure your module name isn’t the same as the project name or you get a “sub or function undefined” error.
Next I wanted to generate an email when I hit the “generate email” button on my form but I got a weird error message.
“A dialog box is open. Please close it and try again.”
Google didn’t help this time so I went to the forum page for the outlook 2007 book I had been using. Which pointed me in the right direction. I googled once again and found that I needed to write
UserForm1.Show vbModeless
I thought that had solved it. Then I went on to make more changes to the code. I ran it again and got the same error. I found that if I changed the code to say.
UserForm1.Show
Ran it, got the error, then changed the code again to
UserForm1.Show vbModeless
Then the code would work. Annoying.
I posted this to the forum and did some more coding. I wrote the email message I wanted to send out and added spots where I can dynamically change the names, email addresses, and whatnot.
I got more help from the outlook forum after clarifying my question. Remember kids, writing clearly is a skill we could all afford to improve on. I found I needed to change the “show modal” property to false. I clicked on my form, then I saw that option on the left hand side. Problem solved.
What I’ve learned so far, or perhaps I should say relearned, is that persistence pays off. You can make this work by using google, getting help from others, and not giving up when you hit a stumbling block.
Next up for me is to find out how to add more than one email address to the bcc (blind carbon copy) field. Off to google I go….