I need help saving an excel xlsm file from an outlook email using excel VBA.
Im modifying an excel VBA that extracts data from lab reports on a server.
I want to add the function where the latest lab report is saved from my email to the server.
I've got the code below, but i get an error saying outlook cannot perferom this action on this type of attachment. The type being xlsm.
Sub Getlabreport()
Dim O As Outlook.Application
Set O = New Outlook.Application
Dim ONS As Outlook.Namespace
Set ONS = O.GetNamespace("MAPI")
Dim ORIG_FOL As Outlook.Folder
Set ORIG_FOL = ONS.GetDefaultFolder(olFolderInbox)
For Each Item In ORIG_FOL.Items
For Each Atmt In Item.Attachments
If Atmt.FileName = Range("Lab_file").Value Then
FileName = Range("Save_folder").Value & "\" & Atmt.FileName
Atmt.SaveAsFile FileName
Exit Sub
End If
Next Atmt
Next Item
End Sub
Is there a work around for this?
Thanks,
What kind of attachment is it? Make sure it is Attachment.Type == olByValue
(1). Outlook cannot save embedded OLE attachments ( olOle
== 6), you'd need Redemption for that if you are using VBA.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.