Microsoft Outlook Code Samples
Resend This Message -- automation code -- added 2/25/2008
Event Code to move emails -- added 4/27/2008
Send files automatically from Outlook -- added 5/15/2008
ItemSend Event Code Etiquette Reminder -- added 8/11/2008
Redirect messages programmatically -- added 8/11/2008
Create Followup Task Reminders -- added 8/11/2008
Automate Outlook -- added 8/11/2008
Export Calendar Items from Outlook to Excel using VBA -- added 8/12/2008
Lunch Special
A routine (that works in Excel as well) that pops up a MsgBox with a random msg. In this case, it a fun app that helps me choose what to eat for lunch. I can see many other uses for this code. I use the same code in the Application_Startup event to pop up a random msg when Outlook starts.
Sub PickLunchForMe()
Dim X As Integer
Randomize
X = Int((5 - 1) * Rnd + 1)
Select Case X
Case 1
MsgBox "Deli"
Case 2
MsgBox "Spanish food"
Case 3
MsgBox "Chinese food"
Case 4
MsgBox "Diner (American food)"
Case 5
MsgBox "Tex Mex"
Case Else
End Select
End Sub
I attach this code to a toolbar button to run it on demand. If you have a different number of options, simply change the "5" in the code to whatever number you want. For example, if you had 10 options, the code would read X = Int((10 - 1) * Rnd + 1). Then you would need to add additional "Case" statements as appropriate. Hopefully your meal choices are better than mine.
Create Excel Workbook (From Outlook)
This is a simple routine that generates a blank Excel workbook from Outlook. Remember to set a reference to the Excel application library from the Outlook VBIDE. You don't have to set the workbook Visible property to True if you want to write anything to it. At this point you can you use any Excel VBA techniques on the workbook -- they work the same as if we were operating in the Excel VBIDE.
Sub CreateXLWorkbook() Dim xlApp As Excel.Application Dim xlWkb As Excel.Workbook Set xlApp = New Excel.Application Set xlWkb = xlApp.Workbooks.Add xlApp.Visible = True Set xlApp = Nothing Set xlWkb = Nothing End Sub
Visit Code For Excel And Outlook Blog