M
matt
I am trying to create the following sub to save an email message as an Excel
file. The Sub does search through the outlook folder and saves the message as
"Daily Processing Report.xls", but I get an error when trying to open it,
"File Format invalid". I am able to do this manually by opening the message
and doing a file save as and typing "Daily Processing Report.xls" and it
opens just fine. But when I do it manually it also saves a folder with the
same name and in it it has two xml files and one file with .thmx extension. I
want to be able to do this with a macro if possible.
sub extractEmailMessage()
Dim olApp As outlook.Application
Dim olNs As outlook.NameSpace
Dim olFolder As outlook.Folder
Dim olItem As outlook.MailItem
Set olApp = CreateObject("Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
Set olFolder = olNs.GetDefaultFolder(olFolderInbox).Folders("Folder")
dirname = "D:\Emails\"
For Each olItem In olFolder.Items
If olItem.Class = olMail Then
olItem.SaveAs dirname & "Daily Status Report.xls"
End If
Next
End Sub
file. The Sub does search through the outlook folder and saves the message as
"Daily Processing Report.xls", but I get an error when trying to open it,
"File Format invalid". I am able to do this manually by opening the message
and doing a file save as and typing "Daily Processing Report.xls" and it
opens just fine. But when I do it manually it also saves a folder with the
same name and in it it has two xml files and one file with .thmx extension. I
want to be able to do this with a macro if possible.
sub extractEmailMessage()
Dim olApp As outlook.Application
Dim olNs As outlook.NameSpace
Dim olFolder As outlook.Folder
Dim olItem As outlook.MailItem
Set olApp = CreateObject("Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
Set olFolder = olNs.GetDefaultFolder(olFolderInbox).Folders("Folder")
dirname = "D:\Emails\"
For Each olItem In olFolder.Items
If olItem.Class = olMail Then
olItem.SaveAs dirname & "Daily Status Report.xls"
End If
Next
End Sub