Hi All,
I would like to create a macro that gets access from Excel to Outlook Calendar (in order to add appointments from worksheet or so). I managed to do that using my own calendar. However, I wish that there were an access for many users.
I have a calendar shared by another user and I am not able to get access to this (also: he isn't able to open mine, using same script). The code I am using is:
Sub WczytywaniePoDacieDlaInUzytkownika()
Dim olApp As Outlook.Application
Dim olNS As Namespace
Dim olFolder As MAPIFolder
Dim costam As Outlook.Recipient
'Dim olApt As AppointmentItem
c01 = DateValue("09-04-2013") + TimeValue("20:00")
c02 = DateValue("09-04-2013") + TimeValue("20:10")
c05 = "ddddd h:mm"
Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")
Set olUser = olNS.CreateRecipient("Another User")
olUser.Resolve
MsgBox olUser.name
If olUser.Resolved Then
MsgBox olNS.Type
olNS.GetFolderFromID
Set olFolder = olNS.GetSharedDefaultFolder(olUser, 9) '.Folders("SubFolder") - It works in both cases, default- and subfolder
'Set olApt = olApp.CreateItem(1)
For Each spra In olFolder.Items.Restrict("[Start]='" & Format(c01, c05) & "'Or [Start]='" & Format(c02, c05) & "'")
MsgBox spra.Subject
Next
'MsgBox olFolder.Items.Find("[Start]='" & Format(c01, c05) & "'").Subject
End If
Set olApp = Nothing
Set olNS = Nothing
Set olFolder = Nothing
Set olApt = Nothing
End Sub
Following the instructions from plenty of threads I replaced "GetDefaultFolder" with "GetSharedDefaultFolder".
If I type my name instead of "Another User" it works perfectly, exactly the same as previously. However typing another name brings me a "Run-time error '-2147221233 (8004010f)'": The operation failed" in line "Set olFolder = olNS.GetSharedDefaultFolder(olUser, 9)"
Has anyone any idea what am I doing wrong? Maybe I type a name in wrong format, but - as I mentioned - using mine in same works, and also resolving works same as it should.
Or maybe You have an idea how to omit with - I guess - creating special, opened calendar.
Thank You very much in advance for Your help,
Andrzej
Bookmarks