Hey,
I'm trying to write a macro that will look at a specific folder C:\Temp and then convert all MSG files (outlook mails) to pdf, keeping the same file names.
I want to clarify the question - i just want to convert the body text (including headers) - no need to convert the attachments at all.
The msg files
The desired results
Since I'm a beginner in VBA, I can't write the code from scratch
Therefore, what I'm actually trying to do is to modify an existing macro that convert docx to pdf, attempting that it will work in the same way with msg files.
I wrote the code below in order to convert msg files located in c:\temp to pdf - but it doesn't work.
As I said above the code doesn't function at all. It may contain a lot of errors.
Is there a way to save MSG files to pdf files?
Maybe there is no way to write a macro that save outlook msg files as pdf file
Save a message as a file
I thought about another idea to deal with the problem, maybe there is a way to write a macro that convert MSG files located in specific folder c:\temp to Doc/x.
A macro that convert MSG files to Doc/x files will help me as well, since I already have a macro to convert docx to pdf. therefore if i could convert msg to doc/x then I can convert docx files to pdf files.
Obviously, if there is a macro that convert MSG to pdf directly it is the Preferred solution, but the alternative suggestion/idea (convert msg files to docx files) will be perfect as well.
I'm trying to write a macro that will look at a specific folder C:\Temp and then convert all MSG files (outlook mails) to pdf, keeping the same file names.
I want to clarify the question - i just want to convert the body text (including headers) - no need to convert the attachments at all.
The msg files
The desired results
Since I'm a beginner in VBA, I can't write the code from scratch
Therefore, what I'm actually trying to do is to modify an existing macro that convert docx to pdf, attempting that it will work in the same way with msg files.
I wrote the code below in order to convert msg files located in c:\temp to pdf - but it doesn't work.
VBA Code:
Sub MsgToPdF()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim OpenSourceFolder As Object, OpenTargetFolder As Object
Dim SelectedOutlookFilesFolder As String, SelectedPdfFilesFolder As String
Dim InputOutlookFile As String, OutputPdfFile As String
Dim objOutlookApp As Outlook.Application
Dim objMyOutlookFile As Word.Document
Set objOutlookApp = CreateObject("Outlook.Application")
SelectedOutlookFilesFolder = "C:\Temp"
SelectedPdfFilesFolder = "C:\Temp"
'Looping through only msg files in input file folder
InputOutlookFile = Dir(SelectedOutlookFilesFolder & "\*.msg")
While InputOutlookFile <> ""
Set objMyOutlookFile = objOutlookApp.Documents.Open(SelectedOutlookFilesFolder & "\" & InputOutlookFile)
objOutlookApp.Visible = True
OutputPdfFile = SelectedPdfFilesFolder & "\" & Replace(objMyOutlookFile.Name, "msg", "pdf")
objOutlookApp.ActiveDocument.ExportAsFixedFormat OutputFileName:=OutputPdfFile, ExportFormat:=wdExportFormatPDF
objMyOutlookFile.Close
InputOutlookFile = Dir
Wend
objOutlookApp.Documents.Application.Quit
End Sub
As I said above the code doesn't function at all. It may contain a lot of errors.
Is there a way to save MSG files to pdf files?
Maybe there is no way to write a macro that save outlook msg files as pdf file
Save a message as a file
I thought about another idea to deal with the problem, maybe there is a way to write a macro that convert MSG files located in specific folder c:\temp to Doc/x.
A macro that convert MSG files to Doc/x files will help me as well, since I already have a macro to convert docx to pdf. therefore if i could convert msg to doc/x then I can convert docx files to pdf files.
Obviously, if there is a macro that convert MSG to pdf directly it is the Preferred solution, but the alternative suggestion/idea (convert msg files to docx files) will be perfect as well.