Accessing shared outlook folder doesn't work since switch to new outlook/excel

elbrodero

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
#1
Hello,

I have a macro that used to work like charm on office 2010. Since the switch to windows 10 and office 365 it only work occasionally. The macro extracts excel files from e-mails that are in a certain sub folder. I am using the macro out of excel.

I used the following code:

Const olFolderInbox As Integer = 6



Sub DownloadAttachmentFirstUnreadEmailSharedMail()
Dim olNamespace As Object
Dim olApp As Object
Dim olNs As Object
Dim olFolder As Object
Dim olRecip As Object
Dim oOlItm As Object
Dim oOlAtch As Object

Set olApp = GetObject(, "Outlook.application")
Set olNs = olApp.GetNamespace("MAPI")
Set olRecip = olNs.CreateRecipient("work@work.de")
Set olFolder = olNs.GetSharedDefaultFolder(olRecip, olFolderInbox).Folders("03_EUR_03")


Unfortunately, the code gets stuck now in the last line giving me the error message "not all object could be found". However, this only happens occasionally.
 
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#2
I wonder if its a GAL issue - for whatever reason, it cant get into the gal and dies. You can try resolving the olRecip before getting the folder -

Set olRecip = olNs.CreateRecipient("work@work.de")
olRecip.Resolve
Set olFolder = olNs.GetSharedDefaultFolder(olRecip, olFolderInbox).Folders("03_EUR_03")

Do you have the offline address book downloaded? Not sure if it will help resolve it faster, but it might.
 

elbrodero

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
POP3
#3
I included the olRecip.Resolve line into my code but unfortunately it is still showing me an error message sometimes for the line:
Set olFolder = olNs.GetSharedDefaultFolder(olRecip, olFolderInbox).Folders("03_sonst_EUR")

As far as I know I do not have the offline address book downloaded. How can I do this?

But I am wondering what the GAL has to do with this?
 
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#4
But I am wondering what the GAL has to do with this?
It needs to find the mailbox for this user - olNs.CreateRecipient("work@work.de")

As far as I know I do not have the offline address book downloaded. How can I do this?
Send/Receive menu, expand Send/Receive Groups button - download address book is near the bottom.

Is the 03 subfolder on your computer? it needs to be in your profile to use the code. Are you caching shared folders? Open the account settings dialog, double click on your account then More Settings - advanced tab to check.
 
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server
#5
I'm having a very similar problem. When I use my macro immediately after opening outlook it works fine. Upon subsequent uses it breaks. If I close and reopen outlook it works again, once.

My macro grabs an e-mail from a shared inbox and copies it to a specific user's subfolder, and changes the category to show who it was assigned to and who assigned it to them. It also changes it to "read" in the main inbox and "unread" in the sub inbox. The issue seems to be that this all happens in a shared inbox. Here's a snippet:

Sub Assign(strBox As String, strAddress As String, Name As String, Flag As Boolean, Fwd As Boolean)
Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem
Dim MAILBOX As Outlook.Recipient
Dim User As String
Dim FirstNameLen As Integer
Dim fwditem As Outlook.MailItem
Dim moveitem As Outlook.MailItem
Set objNS = Application.GetNamespace("MAPI")
User = objNS.CurrentUser
FirstNameLen = Len(User) - InStr(1, User, " ")
Set MAILBOX = objNS.CreateRecipient("ACTUAL USER MIALBOX NAME")
MAILBOX.Resolve
Set objInbox = objNS.GetSharedDefaultFolder(MAILBOX, olFolderInbox)
Set objFolder = objInbox.Folders(strBox) 'Code breaks here, but only after running successfully one time


The sub is kicked off from other subs that are unique to each user

Any help is greatly appreciated.
 
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server
#7
Yes the last line of my snippet:
Set objFolder = objInbox.Folders(strBox) 'Code breaks here, but only after running successfully one time

Thanks!
 
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#8
Sorry, I missed the comment in the code earlier. Just saw it now, OOps. :)

Can you post the entire code? I don't see how/where you are setting the value for strBox - best guess is that it is being cleared. Does it give you an error message too?
 
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server
#9
Here is the full code. There are more subs for other users, but I just included one. Some of the code, like the FWD Boolean might not be used anymore. I unchecked the "download shared folders" box under cached exchange mode, and that seems to have worked. I'm not sure if it will keep working. Does it make sense that that would work?

Thanks!

Sub Assign(strBox As String, strAddress As String, Name As String, Flag As Boolean, Fwd As Boolean)
Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem
Dim PLIM As Outlook.Recipient
Dim User As String
Dim FirstNameLen As Integer
Dim fwditem As Outlook.MailItem
Dim moveitem As Outlook.MailItem
Set objNS = Application.GetNamespace("MAPI")
User = objNS.CurrentUser
FirstNameLen = Len(User) - InStr(1, User, " ")
Set MAILBOX = objNS.CreateRecipient("ACTUAL USER MAILBOX NAME")
MAILBOX.Resolve
Set objInbox = objNS.GetSharedDefaultFolder(MAILBOX, olFolderInbox)
Set objFolder = objInbox.Folders(strBox) 'Code breaks here, but only after running successfully one time
If objFolder Is Nothing Then
MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER"
Exit Sub
End If
Set objItem = ActiveExplorer.Selection.Item(1)
If objItem.Class = olMail Then
objItem.UnRead = False
objItem.Categories = ""
objItem.Categories = "Assigned To " & Name & " by " & Right(User, FirstNameLen)
objItem.Close (olSave)
Set moveitem = objItem.Copy
If Flag = True Then
moveitem.FlagIcon = 6
End If
moveitem.Categories = ""
moveitem.Categories = "Assigned To " & Name & " by " & Right(User, FirstNameLen)
moveitem.UnRead = True
moveitem.Move objFolder
End If
Set objItem = Nothing
Set objFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing
End Sub

Sub John()
Assign "JSmith", "john.smith", "John", False, True
End Sub
 
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#10
I thought maybe you were setting strBox then discarding it. But that's not the cause.

Since it works in classic online, I wonder if there was a problem resolving the name in the offline gal.
 
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server
#11
I thought maybe you were setting strBox then discarding it. But that's not the cause.

Since it works in classic online, I wonder if there was a problem resolving the name in the offline gal.
It seems to have worked when I unchecked the download shared folders box (for one user, but not every user). What is a gal?
 
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#12
gal = "Global Address List" - its the address book with all of the internal users in it.
 
Top