Outlook 2013의 공유 사서함에서 매크로를 실행하는 방법

Outlook 2013의 공유 사서함에서 매크로를 실행하는 방법

내 사서함뿐만 아니라 공유 사서함으로도 작업하고 있습니다. 내가 받은 전자 메일에 첨부 파일을 자동으로 저장하는 매크로가 있지만 이것은 내 사서함에만 작동하고 공유 사서함에는 작동하지 않습니다. 어떻게 하면 이런 일이 일어날 수 있는지 알려주실 수 있나요?

이것이 내가 지금까지 가지고 있는 것입니다:

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

답변1

받은편지함 공유에서 실행하려면 다음을 수정해 보세요.암호

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("[email protected]") '// Owner's email address
  Set Folder = Ns.GetSharedDefaultFolder(olShareName, olFolderInbox) '// Inbox
  Set Items = Folder.Items
End Sub

관련 정보