Record Appointment to Calendar on "Public Folder"

djsupersain

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Hi All,

Please if anyone can help that would be greatly appreciated.

I have Office 2016 Desktop connecting to Office365.

I have made a custom form and got the code from here to create a link in the Ribbon etc. It works perfectly to my personal calendar but I would like it to record to a Public Calendar that I have.

Please is someone able to assist with my code?

The structure for my calendar is:

Public Folders - test@test.com
> All Public Folders
>Test Folder
> Test Calendar

Below is my code for the custom form:

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

Thank you so much in advance.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
when you use templates, you need to move the appointment after it is created as it will use the default folder.

Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder

Set objNS = Application.GetNamespace("MAPI")
Set objFolder = objNS.GetDefaultFolder(olPublicFoldersAllPublicFolders).folders("test folder").folders ("test calendar")
objfolder.move newitem


Working with VBA and non-default Outlook Folders

As an FYI, you shouldn't use "too many dots" and should break the lines like this. While it shouldn't be an issue with the path you are using (so either method should be fine), if you go deeper, splitting in into groups like below is better than one long string.
Set objParentFolder = objNS.GetDefaultFolder(olPublicFoldersAllPublicFolders)
Set objFolder = objParentFolder.folders("test folder")
Set myFolder = objFolder.folders ("test calendar")
 

djsupersain

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Hi,

Thank you for your response, greatly appreciated.

I wish I could say I fully understand but I'm a little lost please help? below is what I have amended but still recording to Local Calendar.

Thank you in advance.

Sub MakeItem()
Set newItem = Application.CreateItemFromTemplate("C:\Users\test\AppData\Roaming\Microsoft\Templates\JobBookingNZ.oft")
newItem.Display
Set newItem = Nothing
Set objParentFolder = objNS.GetDefaultFolder(olPublicFoldersAllPublicFolders)
Set objFolder = objParentFolder.folders("test folder")
Set myFolder = objFolder.folders ("test calendar")
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You need to set the folder and move it before you set newitem to nothing.

Code:
Sub MakeItem()
Set objParentFolder = objNS.GetDefaultFolder(olPublicFoldersAllPublicFolders)
Set objFolder = objParentFolder.folders("test folder")
Set myFolder = objFolder.folders ("test calendar")

Set newItem = Application.CreateItemFromTemplate("C:\Users\test\AppData\Roaming\Microsoft\Templates\JobBookingNZ.oft")
newItem.Display
myfolder.move newitem
Set newItem = Nothing
End Sub
 

djsupersain

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Hi,

And again thank you, I'm receiving a "Runtime error 424 object required" ?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
oh - you need to set objNS
Set objNS = Application.GetNamespace("MAPI")
 

djsupersain

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
oh - you need to set objNS
Set objNS = Application.GetNamespace("MAPI")
Hi,

Now getting "Runtime error 438. Object doesn't support this property or method" ?

Sub MakeItem()
Set objNS = Application.GetNamespace("MAPI")
Set objParentFolder = objNS.GetDefaultFolder(olPublicFoldersAllPublicFolders)
Set objFolder = objParentFolder.folders("test folder")
Set myFolder = objFolder.folders ("test calendar")

Set newItem = Application.CreateItemFromTemplate("C:\Users\test\AppData\Roaming\Microsoft\Templates\JobBookingNZ.oft")
newItem.Display
myfolder.move newitem
Set newItem = Nothing
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
sheesh... i transposed the folder and item in the move line - it should be
newItem.Move myfolder

i don't know which is worse - making the mistake or not seeing until now.
 

djsupersain

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Thank you Diane, this is now working :) but...

As soon as I run the macro, it opens my form/appointment, then a pop up with "Responses to this meeting will not be tallied. If you want outlook to tally responses for you, move the meeting to the calendar folder for this account".

Then you click the only option available "OK" and it closes the form/appointment, however I have not been able to even put any details in on that form? But! it does end up on the shared folder :)

Thank you again for all your help.

Outlook 2016 Desktop Application.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
As soon as I run the macro, it opens my form/appointment, then a pop up with "Responses to this meeting will not be tallied. If you want outlook to tally responses for you, move the meeting to the calendar folder for this account".
you can't avoid that when you move meeting requests to a different calendar.


If you weren't use a template, you could use items.add

Set newitem = myFolder .Items.Add(olappointmentitem)

You can try replacing the move line with this:
Set moveCal = newitem .Move(myfolder)
moveCal.display
moveCal.Save
 

djsupersain

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Hi Diane,

Ok, could I add an "item" using a template? with out emailing etc... ?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
no, not to my knowledge. With templates you need to use Move.

But by setting the moved item to a variable, you can work with it after the move. That's what this does:
Set moveCal = newitem .Move(myfolder)
moveCal.display
moveCal.Save

Nothing, short of using your own default calendar, will eliminate the 'will not be tallied' message.
 
Top