[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

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?
0
Crazy_Penguins
Asked:
Crazy_Penguins
  • 2
1 Solution
 
cavehopCommented:
Probably the easiest way is to check if the Subject exists prior to calling the ToString method.
e.g.
If Not objAppointment.Subject Is Nothing
  TempVal = (objAppointment.Subject.ToString).ToString
Else
  TempVal = "(No Subject)"
End If

Hope this helps,
--Lance--
0
 
Crazy_PenguinsAuthor Commented:
Thanks Lance!
0
 
cavehopCommented:
Your most welcome. Glad I could help.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now