Link to home
Start Free TrialLog in
Avatar of Crazy_Penguins
Crazy_Penguins

asked on

VB.NET Reading Outlook Data From Calendar

I am using this code from another solution on this site:

    'In your project include a reference to Microsoft Outlook x.x Object Library
    'where x.x is your version of Outlook
    Dim objApp As Outlook.Application, _
        objNS As Outlook.NameSpace, _
        objCalendar As Outlook.MAPIFolder, _
        objAppointment As Outlook.AppointmentItem
    Set objApp = CreateObject("Outlook.Application")
    Set objNS = objApp.GetNamespace("MAPI")
    'Change OutlookProfileName to the name of your Outlook profile
    objNS.Logon "OutlookProfielName"
    Set objCalendar = objNS.GetDefaultFolder(olFolderCalendar)
   
    'To access each appointment in the calendar do this
    For Each objAppointment In objCalendar.Items
        'Code to do whatever you want to do with each appointment
>      TempVal = (objAppointment.Subject.ToString).ToString
    Next

However I added the part with the >

The problem is if the calendar has no subject, the program crashes.  Can I fix this?
ASKER CERTIFIED SOLUTION
Avatar of cavehop
cavehop
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Crazy_Penguins
Crazy_Penguins

ASKER

Thanks Lance!
Your most welcome. Glad I could help.