PDA

View Full Version : [SOLVED:] problem change Office365 for creating a calendar in Outlook.



Bastringue
12-20-2023, 04:06 AM
Hello,

With Office 2016, the following Excel VBA instruction was working fine to create a new calendar :



Set MyCalendar = namespaceOutlook.Folders(MyOutlookMail).Folders("Calendrier").Folders.Add(CalendrierName)



Unfortunately, it seems this does not work anymore with Office365.
Would you know how to adapt the syntax, please ? (I don't have any O365 at my disposal)
Thank you, Pierre

Jan Karel Pieterse
12-22-2023, 03:32 AM
Are you absolutely sure "Calendrier" is an existing folder name?

Bastringue
12-22-2023, 04:18 AM
Are you absolutely sure "Calendrier" is an existing folder name?

Thanks for your reply... yes, this is the name in the French version of Excel...
For some reason that I don't know, my code loses the value of namespaceOutlook... perhaps because the user "does things" in the open Outlook session that make Excel lose this value... But ultimately , I don't think there is a problem in the syntax of my statement

Jan Karel Pieterse
12-22-2023, 06:21 AM
When is that variable set?

Bastringue
12-22-2023, 09:01 AM
When is that variable set?
Actually, I would like to list the calendars folders in Outlook and I cannot do it (I do it from Office2016 but I cant on Office365). would you have a snippet to print this list out please ?

Aussiebear
12-22-2023, 01:31 PM
Does this work for you?



const olFolderCalendar = 9
const olModuleCalendar = 1
Dim objOL
Dim objNS
Dim objExpCal
Dim objNavMod
Dim objNavGroup
Dim objNavFolder
Dim objFolder
Dim colExpl
dim s
s = ""
set oApp = CreateObject("Outlook.Application")
Set objNS = oApp.Session
Set colExpl = oApp.Explorers
Set objExpCal = objNS.GetDefaultFolder(olFolderCalendar).GetExplorer
Set objNavMod = objExpCal.NavigationPane.Modules.GetNavigationModule(olModuleCalendar)
For Each objNavGroup In objNavMod.NavigationGroups
For Each objNavFolder In objNavGroup.NavigationFolders
On Error Resume Next
Set objFolder = objNavFolder.Folder
If Err = 0 Then
s = s & objNavGroup.Name & " -- " & left(objFolder.FolderPath,30) & vbcrlf
Else
s = s & objNavGroup.Name & " -- " & objNavFolder.DisplayName & " [no permission]" & vbcrlf
End If
On Error GoTo 0
Next
Next
Set oApp = Nothing
Set objNS = Nothing
Set objNavMod = Nothing
Set objNavGroup = Nothing
Set objNavFolder = Nothing
Set objFolder = Nothing
Set colExpl = Nothing
msgbox s

Bastringue
12-22-2023, 03:12 PM
Does this work for you?

Thanks Aussiebear. I have slightly adapted your print like this (messages were truncated):


Set objFolder = objNavFolder.Folder
MsgBox "folder= " & objFolder.FolderPath
MsgBox "objNavGroup.Name= " & objNavGroup.Name
MsgBox "objNavFolder.DisplayName= " & objNavFolder.DisplayName


On 0ffice 2016, I obtain all my folders, in particular the one I have created, named "MyCalendar":

[QUOTE]folder = \\my_mail_adress\Calendrier\MyCalendar
objNavGroup.Name= Mes calendriers
objNavFolder.DisplayName= MyCalendar

This seems coherent with the syntax of my Add method : Set Cal = namespaceOutlook.Folders(MyOutlookMail).Folders("Calendrier").Folders.Add("MyCalendar")

Now I have to check this on Office365 (I can try tomorrow, no Office365 at home)
Thanks again

Bastringue
12-23-2023, 05:31 AM
When I try the snippet on both Outlook365 and Office2016, I obtain the same structure of the Outlook folders:

In particular, if I add "By hand" (on the Outlook window) the calendar named "Fake" to my calendars, I obtain for both versions:

GROUP : Mes calendriers FOLDER NAME: Fake FOLDER PATH: \\MyEmailAdress\Calendrier\Fake

(I have printed this : MsgBox "GROUP : " & objNavGroup.Name ; MsgBox "FOLDER NAME: " & objNavFolder.DisplayName & " -- FOLDER PATH: " & objFolder.FolderPath)

But despite this, if I try to create a new calendar by using VBA like this:


Set MyCalendar = namespaceOutlook.Folders(MyOutlookMail).Folders("Calendrier").Folders.Add(CalendrierName)

It fails on Office365. (it complains about a non found Object... by the way, I have checked on the debugger that MyOutlookMail and CalendrierName are correctly defined)

I don't know what to do...

Bastringue
12-25-2023, 12:27 PM
My problem is "solved". I summarize the question:

The following instruction is working on Office2016 but not on Office365 (for me):

Set MyCalendar = NamespaceOutlook.Folders(MyOutlookMail).Folders("Calendrier").Folders.Add(CalendarName)
Instead of this, I write now:

Set MyCalendar = NamespaceOutlook.GetDefaultFolder(olFolderCalendar).Folders.Add(CalendarNam e)
This instruction works on both Office2016 and Office365.
Still, I don't understand why the first instruction is not working on Office365, and I don't really see the consequences of using the second instead of the first one... someone could explain?...

Aussiebear
12-25-2023, 02:06 PM
You may need to take this one up with Microsoft themselves.