0

In Outlook, I have two accounts configured:

  1. my main account / inbox: chip@mail.com
  2. a shared mailbox: shared@mail.com

So there are two different mailboxes.

I hid some default folders in both mailboxes, using VBA.

I want to unhide a default folder in the shared mailbox shared@mail.com.

This is the suggested code:

Option Explicit
  
Public Sub UnHideFolders()

Dim oFolder As Outlook.Folder
Dim oPA As Outlook.propertyAccessor
Dim PropName, Value, FolderType As String

PropName = "http://schemas.microsoft.com/mapi/proptag/0x10F4000B"
Value = False
 
Set oFolder = Session.GetDefaultFolder(olFolderNotes)

Set oPA = oFolder.propertyAccessor

oPA.SetProperty PropName, Value
 
Set oFolder = Nothing
Set oPA = Nothing
End Sub

This works for the first mailbox account / inbox chip@mail.com.

How do I unhide folders in the second account / shared mailbox?

Community
  • 1
  • 1
Chip
  • 1
  • 1

2 Answers2

1

The following code can be used for getting the folder object that represents the default folder of the requested type for the current profile; for example, obtains the default Notes folder for the user who is currently logged on:

Set oFolder = Session.GetDefaultFolder(olFolderNotes)

To get folders from a shared account you need to use the NameSpace.GetSharedDefaultFolder method which returns a Folder object that represents the specified default folder for the specified user. This method is used in a delegation scenario, where one user has delegated access to another user for one or more of their default folders (for example, their shared Calendar folder). The following code illustrates a possible usage of the method to get a shared calendar folder:

Sub ResolveName() 
 Dim myNamespace As Outlook.NameSpace 
 Dim myRecipient As Outlook.Recipient 
 Dim CalendarFolder As Outlook.Folder 
 
 Set myNamespace = Application.GetNamespace("MAPI") 
 Set myRecipient = myNamespace.CreateRecipient("shared@mail.com") 
 myRecipient.Resolve 
 If myRecipient.Resolved Then 
   Call ShowCalendar(myNamespace, myRecipient) 
 End If 
End Sub 
 
Sub ShowCalendar(myNamespace, myRecipient) 
 Dim CalendarFolder As Outlook.Folder 
 
 Set CalendarFolder = myNamespace.GetSharedDefaultFolder(myRecipient, olFolderCalendar) 
 CalendarFolder.Display 
End Sub

Note, the NameSpace.CreateRecipient method accepts the name of the recipient - it can be a string representing the display name, the alias, or the full SMTP email address of the recipient.

If that is not a standard folder or visible in Outlook you may consider using the Store.GetDefaultFolder method which returns a Folder object that represents the default folder in the store and that is of the type specified by the FolderType argument. This method is similar to the GetDefaultFolder method of the NameSpace object. The difference is that this method gets the default folder on the delivery store that is associated with the account, whereas NameSpace.GetDefaultFolder returns the default folder on the default store for the current profile.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Thanks for your reply & your support. I couldn't manage to get it work, because the actual hidden folder to be unhiden is SyncIssues. How should I change your code to get it work for that folder? – Chip Nov 04 '22 at 10:14
  • You can pass one of the [OlDefaultFolders](https://learn.microsoft.com/en-us/office/vba/api/outlook.oldefaultfolders) enum values to the `GetSharedDefaultFolder` method. – Eugene Astafiev Nov 04 '22 at 10:35
  • So the line would be just: Set CalendarFolder = myNamespace.GetSharedDefaultFolder(myRecipient, olFolderSyncIssues) There hasn't be to changed anything more? – Chip Nov 04 '22 at 10:48
  • Yes, you need to specify the required folder. – Eugene Astafiev Nov 04 '22 at 10:51
0

To get the folder, try

Set oFolder = Session.Accounts("shared@mail.com").DeliveryStore.GetDefaultFolder(olFolderNotes)

... then re-use your existing code to manage the folder.

JohnM
  • 2,422
  • 2
  • 8
  • 20
  • That is valid for regular accounts configured in Outlook only, but not shared ones. – Eugene Astafiev Nov 04 '22 at 09:25
  • Doh! Read the question, John. @EugeneAstafiev At the risk of downvotes, I'll leave the answer here as 'mistake to avoid'! – JohnM Nov 04 '22 at 09:49
  • @JohnM You're my hero! You made my day! It worked like a charm! Problem is solved right now. Where have you been in the last 11 hours? ;-) I'd have slept much better. :) – Chip Nov 04 '22 at 10:11
  • The accounts versus mailboxes issue is due to Microsoft using the word account for mailbox/email address in UI documentation. VBA is stricter. Without having the OP prove they know the difference, a response for either an account or a mailbox could benefit the OP or subsequent searchers. https://stackoverflow.com/a/55361724/1571407 – niton Nov 04 '22 at 11:10