none
Cannot delete ICS calendar opened using VBA (OpenSharedFolder) without Outlook restart RRS feed

  • Question

  • I am trying to write a small VBA application in Outlook 2010 to automatically synchronize calendars around our small office, which doesn't have an Exchange server.  I'm trying to do this by having each user's calendar written to a common location, and then having each user's Outlook automatically pull in the ICS calendars from that location.

    When I use Session.OpenSharedFolder(...), I can successfully open the ICS folders from my test repository with no problem.  However, once the calendar is loaded into Outlook, the permissions appear to be set read-only somehow: if I try then to delete the calendar either manually or programatically, the attempt fails with an error -2147352567 (800200009):

        Cannot delete this folder. Right-click the folder, and then click Properties to check
        your permissions for the folder.  See the folder owner or your administrator
        to change your permissions.

    (As far as I can tell, there are no 'permissions' to be set within the properties dialog of this or any other calendar.)  In any event, once I quit and restart Outlook, it's then possible to delete the previously-undeletable calendar with no problem.

    If I manually use 'File > Open > Open Calendar' to import the ICS, I do not have this permissions problem -- I can delete the imported calendar w/o an Outlook restart.

    Do I need to finesse the permissions somehow when I import the calendar through VBA?  If so, how?  The object model documentation for OpenSharedFolder doesn't seem to indicate what the solution might be.


    Thanks,
    Brian


    Problem code:

    Sub opener()
        Dim ns As NameSpace, fd As Folder, nfd As Folder
        
        Set ns = Application.GetNamespace("MAPI")
        Set fd = ns.GetDefaultFolder(olFolderCalendar)
        
        Set nfd = fd.Session.OpenSharedFolder(Environ("HOMEDRIVE") & _
                Environ("HOMEPATH") & "\Documents\test.ics")
      
        nfd.Delete    '  Error raised at this line
        
    End Sub


    • Edited by Brian Skinn Monday, July 16, 2012 3:38 PM Add code formatting
    Thursday, July 12, 2012 8:22 PM

All replies

  • Hi Brian,

    Thanks for posting in the MSDN Forum.

    I would recommend you access the AppointmentItem form the Calendar folder via Items.Find method then deleted it. following is a sample which works fine on my side.

    I hope it can help you.

    Sub test()
        Dim AppointmentItem As AppointmentItem
        Dim id As String
        Set AppointmentItem = Application.Session.OpenSharedItem("C:\*****\test.ics")
        
        AppointmentItem.Display
        AppointmentItem.Save
        id = AppointmentItem.Subject
        MsgBox id
        AppointmentItem.Close (olSave)
        Set AppointmentItem = Nothing
        Application.Session.GetDefaultFolder(olFolderCalendar).Items.Find("[Subject] = '" & id & "'").Delete
    End Sub
    

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us


    Monday, July 16, 2012 5:54 AM
    Moderator
  • Tom,

    Thanks for your response; however, you've misunderstood the type of the object with which I'm attempting to work.  Your example imports and deletes an individual AppointmentItem from an appointment-type ICS file, whereas I want to import entire calendars from calendar-type ICS files, as well as delete them.

    An attempt to modify my code to use an approach similar to what you describe did not resolve the problem:

    Sub opener()
        Dim ns As NameSpace, fd As Folder, nfd As Folder, id As String
        
        Set ns = Application.Session
        Set fd = ns.GetDefaultFolder(olFolderCalendar)
        
        Set nfd = fd.Session.OpenSharedFolder("C:\...\test.ics")
        
        id = nfd.EntryID
        
        Set nfd = Nothing
        
        ns.GetFolderFromID(id).Delete ' Error still raised here; I've checked, and the ID in 'id' is correct
        
    End Sub

    I had previously thought of the possibility that a residual reference of an identifier to the Folder might have been locking the Folder from deletion somehow, but clearing the reference doesn't resolve the issue.

    Is there possibly a MAPI property not exposed by the object model that could be tweaked via a PropertyAccessor call?

    Thank you,
    Brian

    Monday, July 16, 2012 12:44 PM
  • Tom,

    To note, rewriting the routine avoiding the use of Folder identifiers entirely still doesn't eliminate the problem:

    Sub opener()
    
        Dim id As String
    
        id = Application.Session.OpenSharedFolder("C:\...\test.ics").EntryID
    
        Application.Session.GetFolderFromID(id).Delete ' Error still raised here
    
    End Sub

    -Brian

    Monday, July 16, 2012 3:05 PM
  • Hi Brian,

    I can reproduce the problem you are seeing and it appears to be a bug. After it's open, the file lock on the ICS file is released, so that's not the issue. Apparently there is something else going on where Outlook is not properly initializing the permissions (or something like that) when the ICS file is opened through the object model. I can see the error when clicking on the Permissions tab on the folder properties, and this goes away after Outlook is restarted.

    I will do some more checking to see what I can find out, but there doesn't appear to be a simple way around this issue.


    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    Wednesday, August 1, 2012 9:48 PM
    Moderator
  • Thanks for taking a look at it, Bill.

    Your guess is pretty much what I suspected, that it's some quirk under Outlook's hood.

    To note further: to the best of my ability to determine, it's not a glitch in the underlying MAPI properties.  I'd have to search my history to retrieve the (possibly incomplete) list of MAPI properties that I examined, but the entire set of them was unchanged for the imported calendar Folder before and after Outlook restart.

    A somewhat unrelated question: Are you operating in an Exchange environment?  I'm running standalone (non-Exchange, Win7 Home Premium), and when I open the Properties dialog for this folder (or any folder in Outlook, actually) I don't see a Permissions tab.

    -Brian



    • Edited by Brian Skinn Wednesday, August 8, 2012 1:08 PM Clarity
    Thursday, August 2, 2012 12:09 AM
  • Hi Brian,

    I wasn't able to find a workaround for this, so I think the best I can suggest would be for you to open a support incident so we can see if we can get this fixed as a hotfix. Also, I was testing with an Exchange account (along with a hotmail/msn/live account and also various PSTs loaded).


    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    Wednesday, September 12, 2012 8:11 PM
    Moderator
  • Bill,

    Thanks for looking into this for me.

    Could you direct me to the appropriate location from which to open the support incident, as you suggest?

    Thanks,

    Brian

    Friday, September 14, 2012 1:55 PM
  • Hi Brian, this is the current page for submitting support incident for Office 2010:

    http://support.microsoft.com/ph/13615

    Please just be sure to submit a "Professional" incident since all developer-related issues fall into that category. Also, if you have a MSDN subscription, you may have some free incidents as part of that. But if not, and you need to pay for this up-front, this is clearly a bug so the charge would be refunded to you at the end.


    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    Friday, September 14, 2012 3:06 PM
    Moderator