Você está na página 1de 2

' ' ' '

Automating Outlook from Excel NOTE: Must include a reference to the installed Outlook library under TOOLS | REFERENCES in the VBE ***********************************************************************

' Proc15 creates several new items in Outlook folders. Sub ExcelRoutines_Proc15_AddOutlookItems() Dim OutlookApp As Object Const olMailItem = 0 Const olAppointmentItem = 1 Const olContactItem = 2 Const olTaskItem = 3 Const olJournalItem = 4 Const olNoteItem = 5 Const olPostItem = 6 Const olPink = 2 Set OutlookApp = CreateObject("Outlook.Application") With OutlookApp.CreateItem(olTaskItem) .Subject = "New Task from Excel" .DueDate = Now() .Save End With With OutlookApp.CreateItem(olContactItem) .Save .LastName = "Jones" .FirstName = "Robert" .BusinessTelephoneNumber = "(703) 555-1212" .Save End With With OutlookApp.CreateItem(olNoteItem) .Body = "Learn the Outlook object model!" .Color = olPink .Save End With With OutlookApp.CreateItem(olAppointmentItem) .Start = Date & " 2:00 pm" .End = Date & " 3:00 pm" .Subject = "Meet with staff re Outlook object model." .Save End With With OutlookApp.CreateItem(olJournalItem) .Subject = "Entry made by Excel." .Type = "Excel 97 Developer's Handbook" .Start = Now .Save End With With OutlookApp.CreateItem(olMailItem) .Subject = "Test message" .Body = "This is a test message." .To = "Steve" .Save 'Since the addressee will not be recognized, 'we just save the message into 'a folder instead of calling the send method '.Send End With With OutlookApp.CreateItem(olPostItem) .Subject = "Test posting" .Body = "This is a test posting."

.Save 'Since we don't want to actually post 'this message, we just save it into 'a folder instead of calling the post method '.Post End With End Sub

Você também pode gostar