none
Add Appointment Item to Shared Calendar from Multiple Users RRS feed

  • Question

  • So here is what I have: I have a shared Calendar, called "Site Visits". That I have written a macro to add appointment items to the calendar. The macro is ran via a button on the toolbar, and it will ultimately be installed on several employees' computers.

    The purpose of the code is to create a User Form from which the user can select a number of employees, input a date and site(s), and then Log the trip. When the user logs the trip it sends out a group email to everyone and saves the date as an appointment to the shared calendar.

    Currently, the code runs like a dream on my system. However, when I share the calendar with another user and import the module and useform to his system it bugs out when setting the Calendar Folder if I specify the calendar using the .Folders(CALENDAR NAME AS STRING) function. When I delete this identifier, it will set the calendar but when I try to add the appointment item to the calendar using the Object.Items.Add("IPM.Appointments"), it bugs out. Any help would be appreciated.

    Private Sub CommandButton3_Click()
      Dim objOutlook As Outlook.Application
              Dim objOutlookMsg As Outlook.MailItem
              Dim objOutlookRecip As Outlook.Recipient
              Dim objOutlookAttach As Outlook.Attachment
              Dim grp As Outlook.DistListItem
    Dim myolApp As Outlook.Application
    Dim mynamespace As NameSpace
    Dim mycalendar As Object
    Dim myrecipient As Outlook.Recipient
    
    
    Set myolApp = CreateObject("Outlook.Application")
    Set mynamespace = myolApp.GetNamespace("MAPI")
    Set myrecipient = mynamespace.CreateRecipient("Site Visits")
    
    myrecipient.Resolve
    
    Set mycalendar = mynamespace.GetSharedDefaultFolder(myrecipient, Outlook.OlDefaultFolders.olFolderCalendar).Folders("Site Visits")
    
    Set olapt = mycalendar.Items.Add(olAppointmentItem)
              

    I've only included the code that pertains to the issue. If you need to see more code to get a better understanding of what is going on please let me know.

    Cheers.

    Monday, June 9, 2014 10:49 PM

All replies

  • Hello,

    > it will ultimately be installed on several employees' computers.

    VBA macros are not designed for distributing on multiple PCs. I'd recommend developing a COM add-in instead. See Managed add-ins built with Visual Studio (VSTO) for more information in MSDN. The Outlook Solutions section provides all the required walkthroughs.

    > However, when I share the calendar with another user and import the module and useform to his system it bugs out when setting the Calendar Folder

    Did you try to debug the code? What error message/code do you get?

    I'd recommend breaking the chain of calls, declare each property and method call on a separate line. Thus, you will be able to find a problematic property or method easily.

    You can try to use OpenSharedFolder method of the Namespace class.

    Do you get a valid folder using the GetSharedDefaultFolder method of the Namespace class? Did you check out the return value?

    > it bugs out

    Could you please be more specific? Error code/message?

    Does the user have required permissions for adding new appointments?

    Tuesday, June 10, 2014 9:15 AM