CodeItBetter Programming Another VB Programming Blog

Outlook Automation

Posted on December 15, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'MS Office - Outlook Automation
Sub Main()
    ' Start Outlook.
    ' If it is already running, you'll use the same instance...
    Dim olApp As Outlook.Application
    Set olApp = CreateObject("Outlook.Application")
 
    ' Logon. Doesn't hurt if you are already running and logged on...
    Dim olNs As Outlook.NameSpace
    Set olNs = olApp.GetNamespace("MAPI")
    olNs.Logon
 
    ' Create and Open a new contact.
    Dim olItem As Outlook.ContactItem
    Set olItem = olApp.CreateItem(olContactItem)
 
    ' Setup Contact information...
    With olItem
        .FullName = "Test Kie"
        .Birthday = "9/15/1945"
        .CompanyName = "ABC Co."
        .HomeTelephoneNumber = "123-315-1245"
        .Email1Address = "Aseer@ace.com"
        .JobTitle = "Web Designer"
        .HomeAddress = "5-a I Ave" & vbCrLf & "Tes Park, AY 17242"
    End With
 
    ' Save Contact...
    olItem.Save
 
    ' Create a new appointment.
    Dim olAppt As Outlook.AppointmentItem
    Set olAppt = olApp.CreateItem(olAppointmentItem)
 
    ' Set start time for 2-minutes from now...
    olAppt.Start = Now() + (2# / 24# / 60#)
 
    ' Setup other appointment information...
    With olAppt
        .Duration = 60
        .Subject = "Discussion to discuss plans..."
        .Body = "Discussion with " & olItem.FullName & " to discuss plans."
        .Location = "Home Office"
        .ReminderMinutesBeforeStart = 1
        .ReminderSet = True
    End With
 
    ' Save Appointment...
    olAppt.Save
 
    ' Send a message to your new contact.
    Dim olMail As Outlook.MailItem
    Set olMail = olApp.CreateItem(olMailItem)
    ' Fill out & send message...
    olMail.To = olItem.Email1Address
    olMail.Subject = "About our Discussion..."
    olMail.Body = "Dear " & olItem.FirstName & ", " & vbCr & vbCr & vbTab & _
        "I will call you in 15 minutes for our Discussions!" & _
        vbCr & vbCr & "Btw: I've also added you to my contact list."
    olMail.Send
 
    ' Clean up...
    MsgBox "Done...", vbMsgBoxSetForeground
    olNs.Logoff
    Set olNs = Nothing
    Set olMail = Nothing
    Set olAppt = Nothing
    Set olItem = Nothing
    Set olApp = Nothing
End Sub
Filed under: MS Office Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.