0
當電子郵件進入Outlook中的某個子文件夾時,我在ThisOutlookSession
的以下代碼可以保存來自電子郵件的PDF附件。Outlook 2010 VBA宏保存附件
我以爲我沒有正確使用Initialize Handler,但我試圖改變它,無濟於事。
Public WithEvents myOlItem As Outlook.Items
Dim myOlApp As New Outlook.Application
Public Sub Initialize_handler()
Set myOlItem = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("WAM").Folders("UNPROCESSED").Items
End Sub
Private Sub myOlItem_ItemAdd(ByVal Item As Object)
Dim myOlMItem As Outlook.MailItem
Dim myOlAtts As Outlook.Attachments
Set myOlAtts = myOlMItem.Attachments
Call CallMyProcedure(Item)
End Sub
Sub CallMyProcedure()
Dim itms As Outlook.Items
Dim Itm As Object
' loop through default Inbox items
Set itms = myOlMItem 'Session.GetDefaultFolder(olFolderInbox).Folders("WAM").Folders("UNPROCESSED").Items
For Each Itm In itms
If TypeName(Itm) = "MailItem" Then
' your code is called here
savePDFtoDisk Itm
End If
Next Itm
Set objEmail = Nothing
End Sub
Sub savePDFtoDisk(Itm As Outlook.MailItem)
Dim dateFormat 'Dateiname mit Datum.
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
dateFormat = Format(Now, "mm_yyyy")
saveFolder = "\\marnv006\#marnv006\Bm\Master Scheduling\PC 2.2.11 Work Authorizing Memorandum (WAMs)\WAMS added to WAM Track\"
For Each objAtt In Itm.Attachments
If (InStr(1, objAtt.DisplayName, "WAM", vbTextCompare) > 0) Then
If LCase(Right(objAtt.FileName, 4)) = ".pdf" Then
objAtt.SaveAsFile saveFolder & objAtt.DisplayName
Set objAtt = Nothing
End If 'Nach PDF filtern.
End If
Next
End Sub
我不確定還有什麼可能是錯的,但乍一看我看到你正在傳遞一個參數到CallMyProcedure中,沒有人期待。 – Dave 2014-09-25 15:22:48
*我不明白爲什麼它不起作用,請幫忙!*如果您能詳細說明這意味着什麼,對我們會有所幫助。你有錯誤嗎?如果是這樣,哪一行會引發錯誤,錯誤信息是什麼? – 2014-09-25 15:32:56