Outlook macros to create meeting on shared calendar

Discussion in 'Outlook VBA and Custom Forms' started by djsupersain, Feb 9, 2017.

  1. djsupersain

    djsupersain

    Member
    Hi Guys,

    Thanks for having me here..

    I'm very new to this all and have followed some online guides to customize a "Meeting Form" and create a "Button" on the outlook ribbon allowing me to book jobs. Myself and a work colleague each have independent email addresses on the office365 exchange (we use outlook 2016) and intern also our own calendars.

    I have shared my calendar with my work colleague and have also setup the same form and button on his machine, but everytime he books a job it books to his calendar, at this stage i can only see his booked jobs by sharing his calendar and "Overlaying" with mine so we don't get any conflicting bookings.

    Below is the macro code I used, but what can I add to have it book the jobs on "my calendar" that i have shared with him please.

    Sub MakeItem()
    Set newItem = Application.CreateItemFromTemplate("C:\Users\user\AppData\Roaming\Microsoft\Templates\test.oft")
    newItem.Display
    Set newItem = Nothing
    End Sub

    Thank you so much in advance.
     
  2. Diane Poremsky

    Diane Poremsky

    Senior Member
    that code is not the problem. What permissions does he have to your calendar? Can he create events directly on your calendar using the default form?
     
  3. djsupersain

    djsupersain

    Member
    Hi and thank you for such a quick reply, yes I have set him up as a owner on my calendar.
     
  4. Michael Bauer

    Michael Bauer

    Senior Member
    CreateItem`adds the item to the default calendar, which for your collegue is not yours. Call GetSharedDefaultFolder, and move the item to that folder. See a sample for how to use that function in the VBA help file.
     
  5. djsupersain

    djsupersain

    Member
    Hi Michael thank you for your reply.. very new to this and don't fully understand vb yet but am determined to learn... will the following work ?

    Sub MakeItem()
    Set CalendarFolder = GetSharedDefaultFolder(me@me.com, FolderType)
    Set newItem = Application.CreateItemFromTemplate("C:\Users\user\AppData\Roaming\Microsoft\Templates\test.oft")
    newItem.Display
    Set newItem = Nothing
    End Sub
     
  6. Michael Bauer

    Michael Bauer

    Senior Member
    The email address must be enclosed in quotation marks.
    And you need to move the item to the target folder, that is after loading the template call:
    set newitem=newitem.move(calendarfolder)
     
  7. djsupersain

    djsupersain

    Member
    Hi Michael, thank you again.. so the correct code would be like the following?

    Sub MakeItem()
    Set CalendarFolder = GetSharedDefaultFolder("me@me.com, FolderType")
    Set newItem = Application.CreateItemFromTemplate("C:\Users\user\AppData\Roaming\Microsoft\Templates\test.oft")
    newItem.Display
    Set newItem = newitem.move(calendarfolder)
    End Sub
     
  8. Michael Bauer

    Michael Bauer

    Senior Member
    Only the address is in quotation marks. For FolderType you need to specify which type of folder should be opened: place the cursor onto the word 'FolderType', press ctrl+switch+j, then select the type you need.

    Also, move the item before you display it.
     
  9. djsupersain

    djsupersain

    Member
    Thank you for all your help... slight change in plan, have since created a public folder calendar... please if you could assist in the code below, so now im wanting my macro to create the appointment on the public folder calendar...

    Sub MakeItem()
    Set CalendarFolder = olPublicFoldersAllPublicFolders(TEST, "TEST@TEST.COM" \ TEST_CALENDAR)
    Set newItem = Application.CreateItemFromTemplate("C:\Users\user\AppData\Roaming\Microsoft\Templates\test.oft")
    newItem.Display
    Set newItem = Nothing
    End Sub
     
  10. Michael Bauer

    Michael Bauer

    Senior Member
    Press ctrl+6 in Outlook and look at the hierarchy of folders and their names. You´ll find the same hierarchy in Application.Session.Folders("[here the topfolder name]".Folders("[here the subfolder name]")
     
Loading...

Share This Page