outlook shared mailbox contacts in a excel list with VBA - vba

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

Related

Selecting inbox when multiple exist [duplicate]

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

Outlook VBA Access Folders in Shared Mailbox

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.

How to Hide Item Count in Outlook 2010 with VBA?

This code fails:
Sub Clear_ItemCount()
Dim oAccount As MAPIFolder
Set oAccount = Application.Session.Folders("myaccount#gmail.com")
Dim oInbox As MAPIFolder
Set oInbox = oAccount.Folders("Inbox")
oInbox.ShowItemCount = olNoItemCount
Set oInbox = Nothing
Set oAccount = Nothing
End Sub
Item count is still visible:
According to this article, it seems that it should work. It says it does not work with "Public" folders, but, based on this article, i think "Public" folders are shared folders on an Exchange server (not using an Exchange server).
Is there a way to do this?

VBA Outlook loop through my colleagues tasks

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

NavigationFolders.add() crashes Outlook for shared calendars?

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.

Categories