# vba that creates appointment in shared calendar



## aspiringnerd (Dec 20, 2022)

I'm hoping that it's just as simple as replacing the 3rd line with a different namespace paramater, perhaps namespace.getshareddefaultfolder? I just don't know how to make it work, I'm struggling with the syntax on the ms website. 

I added a comment in the code where I'm pretty sure I need to replace it with but I'm stuck, documentation isn't super clear on my specific need.


```
Sub new_event()
    Set olOutlook = CreateObject("Outlook.Application")
    Set Namespace = olOutlook.GetNameSpace("MAPI")
    Set oloFolder = Namespace.GetDefaultFolder(9) 'this writes to my calendar, but I'd like to write it to a default calendar shared by someone else to me
    
    
    Set Appointment = oloFolder.items.Add
    
    With Appointment
        .AllDayEvent = True
        .Start = Cells(ActiveCell.Row, "T").Value
        .End = Cells(ActiveCell.Row, "U").Value
        .Categories = Cells(ActiveCell.Row, "V").Value
        .Subject = Cells(ActiveCell.Row, "W").Value
        .Display
        
    End With
End Sub
```


----------



## Micron (Dec 20, 2022)

Namespace.GetSharedDefaultFolder(9) ?


----------



## aspiringnerd (Dec 20, 2022)

Micron said:


> Namespace.GetSharedDefaultFolder(9) ?



GetSharedDefaultFolder( _Recipient_ , _FolderType_ )

The syntax has two arguments, 9 is definitely the folder type but for recipient, I tried using the email address but I get a mismatched error.









						NameSpace.GetSharedDefaultFolder method (Outlook)
					

Office VBA reference topic



					learn.microsoft.com
				




from above: "The owner of the folder. Note that the *Recipient* object must be resolved."

for recipient, not sure on the correct syntax or how to 'resolve' the recipient object


----------



## Micron (Dec 20, 2022)

Did you look at the code example there, which resolves the recipient?
Afraid I've never done this, so probably am not helping too much,


----------



## aspiringnerd (Dec 20, 2022)

aspiringnerd said:


> GetSharedDefaultFolder( _Recipient_ , _FolderType_ )
> 
> The syntax has two arguments, 9 is definitely the folder type but for recipient, I tried using the email address but I get a mismatched error.
> 
> ...





Micron said:


> Did you look at the code example there, which resolves the recipient?
> Afraid I've never done this, so probably am not helping too much,


I did solve it, your comment helped me think about it in a different way so I appreciate it.  The solution is as follows:

```
Set myRecipient = Namespace.CreateRecipient("recipient@outlook.com")
    Set oloFolder = Namespace.GetSharedDefaultFolder(myRecipient, 9)
```


----------



## Micron (Dec 20, 2022)

Glad to help, even if only a little bit!


----------

