Macro in Outlook to create signature\other info.

What I'm trying to do is create a macro in Outlook 2003 that will input dial-in information into a calendare entry. Similar to what the "signature" is in an e-mail.
Who is Participating?
David LeeConnect With a Mentor Commented:
Ok.  Here's the code for doing this.  Follow these instructions to add it to Outlook.

1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects
4.  If not already expanded, expand Modules
5.  Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
6.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
7.  Edit the code as needed.  I included comments wherever something needs to or can change
8.  Click the diskette icon on the toolbar to save the changes
9.  Close the VB Editor

Follow these instructions to add a toolbar button you can click to run the code.

1.  Click View->Toolbars->Customize
2.  Click the Toolbars tab
3.  Click New
4.  Name the toolbar
5.  Click the Commands tab
6.  Under Categories click Macros
7.  Under Commands click and hold on the macro, then drag it out and drop it on the new toolbar
8.  Dock the toolbar somewhere onscreen

Sub AddCallinInfo()
    Dim olkAppt As Outlook.AppointmentItem
    Set olkAppt = Outlook.Application.ActiveInspector.CurrentItem
    'Change the number and participant code on the next line'
    olkAppt.Body = "Dial-in Number: xxx-xxx-xxxx" & vbCrLf & "Participant code: 123456789" & vbCrLf & olkAppt.Body
    Set olkAppt = Nothing
End Sub

Open in new window

David LeeCommented:
Hi, Darkejo1.

Simple enough.  What information do you want and do you want it to appear automatically or do you want to click something to have it appear?
Darkejo1Author Commented:
I'd like to be able to hit a button and it add something like a signature. For instance:

Dial-in Number : xxx-xxx-xxxx
Participant code : 123456789
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Darkejo1Author Commented:
Great! That worked. Rather then just see this, can you explain some of it for me?  I understand .vbs, and i can see it's alot like it. Why did you put the info. you did on line 2. I understand the "DIM OLKAPPT", but i don't understand the "AS OUTLOOK.APPOINTMENTITEM".
David LeeCommented:
Sure.  VB Script (VBS) and VB for Applications (VBA), which is what this is written in, are very similar.  The languages are virtually identical as far as command and general language syntax, with VBA adding a few things that VBS does not have.  One of the additions is declaring typed variables.  In VBS all variables are of the "Variant" type.  That is they can store any data type: string, integer, object, etc.  Variables declared in VBA will be of type variant also unless they are declared to be of a specific type.  In this case I declared olkAppt to be of type "Outlook.AppointmentItem".  Declaring a variable to be of a certain type has a number of benefits.  It tells the VB interpreter exactly what type of data the variable will store which: allows the system to reserve the correct amount of memory for it; enforces type checking (I cannot put anything but an appointment in the variable without causing an error); allows the author to see the properties and methods of the object, etc.  I could also have just declared olkAppt without specifying a type.  If I'd done that, then olkAppt would have been of type variant.  The code would still work just fine, but wouldn't take advantages of any of the benefits I listed.  For example, if you have a message open instead of an appointment, then the code would insert the info into it.  In contrast with the variable's type declared running the code with a message open with generate a type mismatch error.  

Does that help?
Darkejo1Author Commented:
Some. How do you know what to use for the "type" You used outlook.appointmentitem. Where did you come up with appointmentitem. and why isnt outlook called microsoftoutlook? is there something that has the different types in it?
David LeeCommented:
There are several ways to know.  First, Microsoft builds something called IntelliSense into the VB editor of any Microsoft Office product that supports VBA.  When you type in a variable declaration IntelliSense displays a popup window that shows you all the type it knows about.  The types fall into a hierarchy.  In simple terms, I know that an appointment is an Outlook specific object, so I start typing Outlook and IntelliSense jumps me to Outlook.  When I hit the period separating Outlook from AppointmentItem IntelliSense changes the list to show all the objects, methods, and properties that are subordinate to Outlook.  Second, if I didn't know any of this, then I could press the F2 key in the VB editor and launch the object browser.  From there I select the Libraries pulldown and select Outlook (since I know I'm looking for a an Outlook specific object).  That loads a list of all the objects, properties, methods, etc. that are specific to Outlook.  Looking down the list I see AppointmentItem.  Third, I can search Outlook's built-in help for Appointment.  That'll find the AppointmentItem object which shows me how to declare a variable of that type along with what properties and methods it supports.
Darkejo1Author Commented:
Wow! that helped alot. It makes perfect sense! Do you know how to make the button an image? Rather then the word project1.macro name? If you do, i'll open another question. Thanks for all the help thus far!
David LeeCommented:
Yes, I know how to make the button an image.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.