This question already has answers here:
Get reference to additional Inbox
(3 answers)
Closed 1 year ago.
Hi I am using the following macro to create a batch of new folders in an inbox. It performs fantastically however I can't for the life of me figure out how to select a different inbox (inbox1, inbox2, inbox3) all different email accounts.
code is here: http://www.slipstick.com/macros/Create%20subfolders%20at%20multiple%20levels.txt
Instead of using Session.GetDefaultFolder, call Session.CreateRecipient / Recipient.Resolve / Session.GetSharedDefaultFolder
If all these inboxes are configured in Outlook you can use the Stores collection to iterate over stores and 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.
If you need to access shared mailboxes you need to use the NameSpace.GetSharedDefaultFolder method which returns a Folder object that represents the specified default folder for the specified user.
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("Dan Wilson")
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
Related
In my Outlook, I have two accounts configured:
my main account / inbox: chip#mail.com
a shared mailbox: shared#mail.com
So there are two different mailboxes.
I could hide some default folders using VBA in both mailboxes.
But now 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 fine for the first mailbox account / inbox chip#mail.com, but I can't get it to work for the second account / shared mailbox shared#mail.com.
How do I have to change the above code to unhide folders in the second account / shared mailbox?
Thanks in advance for your support!
A somehow desperate Chipy
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.
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.
I have some VBA code in Outlook which behaves perfectly for the main Mailbox - however the same code is struggling when I add a secondary mailbox - this is Outlook 2016.
It seems to be struggling with reading the sub folders - I can get it to read mail items in the Inbox, but not the sub folders.
Code :
Dim sharedemail As Outlook.Recipient
Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.MAPIFolder
Dim myDestFolder Outlook.MAPIFolder
Dim strSubject As String
Dim i As Integer
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set sharedemail = myNameSpace.CreateRecipient("recip#domain.com")
Set myInbox = myNameSpace.GetSharedDefaultFolder(sharedemail, olFolderInbox)
For itemCount = myInbox.items.Count To 1 Step -1 'Iterates from the end backwards
Set item = myInbox.items(itemCount)
strSubject = UCase(item.Subject)
Select Case True
Case InStr(strSubject, UCase("Holiday Request")) > 0
'Set destination folder
Set myDestFolder = myInbox.Folders("HolidayRequests")
'move the email out of inbox
item.Move myDestFolder
End Select
Next
It stalls at the Set myDestFolder line as it can't seem to select that sub folder - as I say same code seems to work fine in main Inbox?
Thanks
Keep in mind that Outlook keeps shared default folders in the primary OST file, and it does not sync the subfolders.
You can either
Uncheck the "Download shared folders" checkbox
Use Extended MAPI (C++ or Delphi) - that would be fairly complex as you'd need to retrieve the autodiscover XML for that mailbox and construct the store entry id appropriately.
use Redemption (I am its author) - its version of RDOSession.GetSharedDefaultFolder returns an online version of the folder (RDOFolder) with all its subfolders.
I found how to assign tasks to my colleagues.
Is it possible to loop through my colleagues tasks with filter on project name, so I could monitorate tasks status?
In a team project we assign tasks to each other, and the project manager could in one click see important tasks, their status, due date...
You can use the GetSharedDefaultFolder method of the Namespace class to get a Folder object that represents the specified default folder for the specified user. For example, to get the shared tasks folder you can use the following code:
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("Eugene Astafiev")
myRecipient.Resolve
If myRecipient.Resolved Then
Call ShowTasks(myNamespace, myRecipient)
End If
End Sub
Sub ShowTasks(myNamespace, myRecipient)
Dim TaskFolder As Outlook.Folder
Set TaskFolder = _
myNamespace.GetSharedDefaultFolder _
(myRecipient, olFolderTasks)
TaskFolder.Display
End Sub
Simple enough line here:
Set navFol = navGroup.NavigationFolders.Add(cal)
This works as expected for any local calendars, but it instantly crashes Outlook if "cal" is a shared calendar. Anyone know a workaround to move shared calendars around between navigation folders? I'm quite new to VBA, just hacking my way around to get a macro to do a simple something for me -- or at least something which really should be simple if not for this.
I doubt it matters, but just in case, "cal" is being set in a for loop by iterating through a list of EntryIDs like so:
Set cal = Application.GetNamespace("MAPI").GetFolderFromID(str)
And it's not the variable assignment that's failing there (which is why the above line should be irrelevant). I can do anything else with the calendar whether or not it's shared: read the name, grab appointments from it, etc. Outlook just apparently does not like using shared calendars as arguments for NavigationFolders.Add().
EDIT: I'm talking about NON-default calendars shared via sharing invitations. GetDefaultSharedFolder or the like isn't what I want.
Try to use the GetSharedDefaultFolder method of the Namespace class to get the shared folder instead.
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("Eugene Astafiev")
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
The Add method of the NavigationFolders class adds the specified Folder, as a NavigationFolder object, to the end of the NavigationFolders collection.
I'm looking for a vba code in excel, he should contacts from a shared mailbox (different exchange account called shared mailbox in outlook) transfer to a excel list, with the normal contacts from outlook it works I used this:
Set nsOutlook = applOutlook.GetNamespace("MAPI")
Set cfOutlook = nsOutlook.GetDefaultFolder(olFolderContacts)
with Set olcontacts = cfOutlook.Folders("name")
I have used the "name" where is displayed in outlook
it not works he not find the folder.
is there a solution without recipient?
because there will be several user-all with the same shared mailbox
I hope you can help me.
The Outlook object model provides the GetSharedDefaultFolder method of the Namespace class which returns a Folder object that represents the specified default folder for the specified user. For example:
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("Dan Wilson")
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