我從ERP系統接收系統生成的電子郵件,其中包含.zip文件,zip文件內部是一個包含要導入儀表板的數據的excel文件我擁有製作。Outlook VBA解壓縮附件並保存到文件夾
目前,我有這樣的代碼,其成功保存的.zip附件到該文件夾時,我收到的電子郵件:
Sub saveAttachment2(Item As Outlook.MailItem)
Dim selItems As Selection
Dim objItem As Object
Dim iCount As Integer
Dim atmts As Attachments
Dim oAttachment As Attachment
Dim sSaveFolder As String
Set selItems = ActiveExplorer.Selection
sSaveFolder = "C:\Users\212357980\Documents\Accounts Coordination\Oracle Exports\"
For Each objItem In selItems
Set atmts = objItem.Attachments
For Each oAttachment In atmts
oAttachment.SaveAsFile sSaveFolder & "\Service Requests.zip"
Next
Next
End Sub
現在我想它解壓縮文件時,它的位置保存之前,這是我到目前爲止有:
Sub Unzip2()
Dim ns As NameSpace 'variables for the main functionality
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim Atchmt As Attachment
Dim FileName As String
Dim msg As Outlook.MailItem
Dim FSO As Object 'variables for unzipping
Dim oApp As Object
Dim FileNameFolder As Variant
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = Inbox.Folders("Sales Orders")
For Each msg In SubFolder.Items
For Each Atchmt In msg.Attachments
If (Right(Atchmt.FileName, 3) = "zip") Then
FileNameFolder = "C:\Users\212357980\Documents\Accounts Coordination\Oracle Exports\"
Set oApp = CreateObject("Shell.Application")
With oApp
.NameSpace(FileNameFolder).CopyHere
.NameSpace(Atchmt.FileName).Items
End With
On Error Resume Next
Set FSO = CreateObject("scripting.filesystemobject")
FSO.deletefolder Environ("Temp") & "\Temporary Directory*", True
End If
Next
Next
End Sub
我得到錯誤的兩線「的參數或無效的屬性賦值錯號」的後帶。
任何幫助你可以提供將是偉大的!
您需要將壓縮保存到臨時文件夾和從那裏提取它:非常確定,如果不先保存它,你就無法做到這一點。 –
「With oApp」塊中的這兩行應該在一行中。 –