VBA in Outlook to refer to inbox other than default

LBissett

New Member
Joined
Apr 10, 2009
Messages
22
Hi all,
Is there a way to refer to a inbox other than the default using VBA? At work, I have access to my email and two others. My VBA is for one of the other mailboxes not my own. My code is below.

Thanks
Lisa


Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim ManualFolder As MAPIFolder
Dim AppRecdFolder As MAPIFolder
Dim Item As MailItem
Dim ItemCopy As MailItem
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer
Dim InFileName As String
Dim FCheck As String
Dim varResponse As VbMsgBoxResult
Dim objXLApp As Object
Dim objXLBook As Object
Dim EMSentDateTime As String
Dim EMReceivedDateTime As String
Dim EMSentDate As Date
Dim EmSentTime As Date
Dim EMReceivedDate As Date
Dim EMReceivedTime As Date
Dim senderAdd As String
Dim EMSubject As String
Dim attachSavePath As String
Dim attachFileName As String
Dim AllAtmtsThere As String
Dim strExt As String


HAFileName = "HACodesForCompEmails.xlsx"
attachSavePath = "J:\Attachments\"
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = Inbox.Folders("Applications")
Set ManualFolder = Inbox.Folders("ApplicationsForManualReview")
Set AppRecdFolder = Inbox.Folders("ApplicationsReceived")
Const EXTENTION As String = " zip"
Const SUBFILE As String = "J:\Applications-Report.csv"

i = 0

' Check subfolder for messages and exit if none found
If SubFolder.Items.Count = 0 Then
MsgBox "There are no messages in the Applications folder.", vbInformation, _
"Nothing Found"
Exit Sub
End If
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I think you need something like this (other user name is James in this example):
Code:
    Set objRecipient = ns.CreateRecipient("James")
    With objRecipient
        .Resolve
        If .Resolved Then
            Set myFolder = ns.GetSharedDefaultFolder(objRecipient, olFolderInbox)
' ... rest of your code can now use myFolder
 
Upvote 0

Forum statistics

Threads
1,225,399
Messages
6,184,752
Members
453,254
Latest member
topeb

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top