How to run a macro on a shared mailbox in Outlook 2013

4

3

I am working with my own mailbox, but also with a shared mailbox. I have a macro to automatically save attachments in e-mails which I receive, but this works only for my own mailbox and not for the shared mailbox. Can you please tell me how I can make this happen?

This is what I have so far:

Private Declare Function ShellExecute Lib "shell32.dll" Alias _
  "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
  ByVal lpFile As String, ByVal lpParameters As String, _
  ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
  Dim Ns As Outlook.NameSpace
  Dim Folder As Outlook.MAPIFolder

  Set Ns = Application.GetNamespace("MAPI")
  Set Folder = Ns.GetDefaultFolder(olFolderInbox)
  Set Items = Folder.Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
  If TypeOf Item Is Outlook.MailItem Then
    PrintAttachments Item
  End If
End Sub

Private Sub PrintAttachments(oMail As Outlook.MailItem)
  On Error Resume Next
  Dim colAtts As Outlook.Attachments
  Dim oAtt As Outlook.Attachment
  Dim sFile As String
  Dim sDirectory As String
  Dim sFileType As String

  sDirectory = "I:\Finance_Administration\MMR\Attachments\"

  Set colAtts = oMail.Attachments

  If colAtts.Count Then
    For Each oAtt In colAtts

' This code looks at the last 4 characters in a filename
      sFileType = LCase$(Right$(oAtt.FileName, 4))

      Select Case sFileType

' Add additional file types below
      Case ".xls", ".doc", "docx", ".pdf"

         sFile = sDirectory & oAtt.FileName
         oAtt.SaveAsFile sFile
        'ShellExecute 0, "print", sFile, vbNullString, vbNullString, 0
      End Select
    Next
    End If
End Sub

JJOWPS

Posted 2016-02-03T11:13:11.720

Reputation: 41

1

Take a look here. I hate shared exchange accounts. It's probably easier to just use a rule to trigger a download macro.

– Raystafarian – 2016-02-03T18:33:28.273

Answers

4

To run it on share inbox, Try Modifying your code

Example

Private Sub Application_Startup()
  Dim Ns As Outlook.NameSpace
  Dim Folder As Outlook.Folder
  Dim olShareName As Outlook.Recipient


  Set Ns = Application.GetNamespace("MAPI")
  Set olShareName = Ns.CreateRecipient("Om3r@Email.com") '// Owner's email address
  Set Folder = Ns.GetSharedDefaultFolder(olShareName, olFolderInbox) '// Inbox
  Set Items = Folder.Items
End Sub

0m3r

Posted 2016-02-03T11:13:11.720

Reputation: 937