none
openshareditem vba script throws an error invalid path or url (Outlook) RRS feed

  • Question

  • Hi All,
    I have a short VBA code. I am trying to import a ics file into Outlook 2016. Running on Server 2012 R2.

    I got the code from here --> https://gallery.technet.microsoft.com/office/Open-the-icsical-file-49e2263c

    This is my code:

    Public Sub OpeniCal()
      
     'Declaration
     Dim oNamespace As NameSpace
     Dim oSharedItem As AppointmentItem
        
     ' Get a reference to a NameSpace object.
     Set obNamespace = Application.GetNamespace("MAPI")
      
     ' Open the iCal file containing the shared item and display it
     Set oSharedItem = obNamespace.OpenSharedItem("C:\temp\ICS\EventCalendar.ics")
     'oSharedItem.Display
      
     'Save the ical to your Calendar
     oSharedItem.Save
     
    End Sub

    When reaching the line 

    Set oSharedItem = obNamespace.OpenSharedItem("C:\temp\ICS\EventCalendar.ics")

    I get an error - Run-time error '440': Invalid path or URL.

    What is wrong? how should it be fixed?

    Thanks!
    S

    Tuesday, August 13, 2019 5:37 AM