Outlook.Mailitem无法被另一个子调用

时间:2019-03-01 09:06:41

标签: vba outlook outlook-vba

我正在尝试将电子邮件的附件保存到我的桌面。一个子调用使用Item(1)作为输入的另一个子。到目前为止,我已经知道了,调用子saveAttachtoDisk时会出错。它给出了图片上显示的错误。

Sub Call_saveAttachtoDisk()

Dim objSelection As Outlook.Selection
Dim objMsg As Object 'Object

Set objSelection = ActiveExplorer.Selection

Set objMsg = objSelection.Item(1)

saveAttachtoDisk (objMsg)

End Sub

Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
     Dim objAtt As Outlook.Attachment
     Dim saveFolder As String
     Dim i As Integer

     i = 0
     saveFolder = "C:\Users\peet\Desktop"
     For Each objAtt In itm.Attachments
          i = i + 1
          objAtt.SaveAsFile saveFolder & "\name" & i & ".pdf"
          Set objAtt = Nothing
     Next
End Sub

enter image description here

2 个答案:

答案 0 :(得分:0)

找到了解决方案。

调用子程序之前需要添加Call

Call saveAttachtoDisk (objMsg)

答案 1 :(得分:0)

只需删除括号 ()

示例

saveAttachtoDisk objMsg