0

I wrote a VBA script, and it currently only operates on the first inbox open in outlook.

How do I specify which Inbox it operates on? ie, the Inbox of another account.

I assume somewhere in here -

Sub MoveAgedMail()

Dim objOutlook As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objSourceFolder As Outlook.MAPIFolder
Dim objDestFolder As Outlook.MAPIFolder
Dim objVariant As Variant
Dim lngMovedItems As Long
Dim intCount As Integer
Dim intDateDiff As Integer
Dim strDestFolder As String
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Joshua Patterson
  • 433
  • 1
  • 4
  • 15
  • 2
    This code declares a bunch of variables, but *does nothing*.... – Mathieu Guindon Jan 19 '16 at 03:45
  • Possible duplicate of [Get reference to additional Inbox](http://stackoverflow.com/questions/9076634/get-reference-to-additional-inbox) – niton Feb 17 '16 at 13:25
  • Variations of explanations and methods. http://stackoverflow.com/questions/28310088/using-microsoft-access-need-to-pull-attachments-from-outlook-emails-of-a-differ and http://stackoverflow.com/questions/26274516/vba-get-email-from-non-default-inbox – niton Feb 17 '16 at 13:27

1 Answers1

1

ie, the inbox of another account.

Assuming your talking about shared Inbox

VBA Example Code will be

Option Explicit
Sub OpenShareInbox()
    Dim olNameSpace As Outlook.NameSpace
    Dim olRec As Outlook.Recipient
    Dim olFolder As Outlook.Folder

    Set olNameSpace = Application.GetNamespace("MAPI")
    Set olRec = olNameSpace.CreateRecipient("Om3r@Email.com") '// Owner's email address
    Set olFolder = olNameSpace.GetSharedDefaultFolder(olRec, olFolderInbox)

    MsgBox olRec.Name '// Owner Name

    olFolder.Display '// Open Inbox
End Sub

Edit:

Here is another Example - Open your immediate window and print Subject line

Option Explicit
Sub OpenShareInbox()
    Dim olNameSpace As Outlook.NameSpace
    Dim olRec As Outlook.Recipient
    Dim olFolder As Outlook.Folder

    Dim olItem As Outlook.MailItem

    Set olNameSpace = Application.GetNamespace("MAPI")
    Set olRec = olNameSpace.CreateRecipient("Om3r@Email.com") '// Owner's email address
    Set olFolder = olNameSpace.GetSharedDefaultFolder(olRec, olFolderInbox) '// Inbox


    For Each olItem In olFolder.Items
        Debug.Print olItem.Subject
    Next

End Sub

Or Forward Mail Item with Subject line "Report"

For Each olItem In olFolder.Items
    If olFolder.DefaultItemType = olMailItem Then
        If olItem.Class = olMail Then
            If olItem.Subject = "Report" Then
                Set olItem = olItem.Forward
                olItem.Subject = "APPENDED SUBJECT - " + olItem.Subject + ""
                olItem.Recipients.Add "Om3r <Om3r@Email.com>"
                olItem.Display
    '            olItem.Send
            End If
        End If
    End If
Next

See NameSpace.GetSharedDefaultFolder Method (Outlook)on MSDN

0m3r
  • 12,286
  • 15
  • 35
  • 71
  • Thank you, just to clarify - I have multiple exchange accounts linked to the one outlook profile. As it stands my VBA code will only operate on the primary exchange account, but I want to be able to specify which account it acts upon. Will this code achieve this? I am having trouble implementing it. Do I just have to set the variables and dim and then it should work? – Joshua Patterson Jan 21 '16 at 06:22
  • 1
    Yes and Yes, see edit on answer. I don't know what your try to do but try to play with this code and if your still having problem, post new question with your code complete code. – 0m3r Jan 22 '16 at 05:16