Improving Your Outlook

You can write many pieces of code to improve your productivity with Outlook. If you routinely use categories, you can use code to ensure that a category is always assigned to your emails when they are sent. You can also write code that runs whenever a new mail message is received and enables you to choose a category from a drop-down list and assign that category to an item.

You can write code to manipulate any folder or item in Outlook. With the increase in mobile devices and the reduction in time people spend at their desks, a good use of Outlook VBA is to send meeting reminders to a user's pager.

Outlook has a built-in event that triggers when a reminder is launched. Launch the VBA editor and select ThisOutlookSession from the Project Explorer. Click F7 if you aren't already in the code window. Choose Application from the Object drop-down list and Reminder from the Procedure drop-down list. You're now ready to start writing code.

The Reminder procedure is passed one variable: Item. This represents the individual item whose reminder is being launched. Before you write any code, your Reminder procedure looks like the following:

 Private Sub Application_Reminder(ByVal Item As Object) End Sub 

The first step declares all your variables. Because you want to create a new mail item to be delivered to your pager or cell phone, you need a variable for that email item. You can create a new mail item directly from the built-in Application object, so you don't have to declare a NameSpace variable unless you want to do something more than simply send an email.

Declare your object variable and add a statement at the end of your code to set the object variable to Nothing. It's a good idea to create the dimension statement and the Nothing statement at the same time. This ensures that you never forget to release your object variables.

After you've declared your variable, your code should look something like this:

 Private Sub Application_Reminder(ByVal Item As Object) Dim objMailItem As Outlook.MailItem         'Code here to send an email to a digital pager or cell phone. Set objMailItem = Nothing End Sub 

You can create a new mail item using the following line of code:

 Set objMailItem = Application.CreateItem(olMailItem)  

After you have a reference to a mail item, set its various properties in your code. When you're done, your code should look similar to the following:

 Private Sub Application_Reminder(ByVal Item As Object) Dim objMailItem As Outlook.MailItem     'Code here to send an email to a digital pager or cell phone.     Set objMailItem = Application.CreateItem(olMailItem)     objMailItem.To = "8884445555@mycellphone.com"     objMailItem.Subject = Item.Subject     objMailItem.Body = "Reminder for " & Item.Subject     objMailItem.Send Set objMailItem = Nothing End Sub 

This code will send an email to your cell phone or digital pager whenever a reminder is launched.



Special Edition Using Microsoft Office Outlook 2003
Special Edition Using Microsoft Office Outlook 2003
ISBN: 0789729563
EAN: 2147483647
Year: 2003
Pages: 426

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net