ssPatriots
Member
- Outlook version
- Outlook 365 64 bit
- Email Account
- Office 365 Exchange
Hi,
I'm new to this forum. I came here because I found Diane Poremsky's code called "SaveMessagesAndAttachments" and need to see if it can be tweaked to allow me to start with a defined file path and once the dialog box opens, give me the opportunity to drill down a couple folders form there to place all the files that are created. Ideally, I would like to have the Outlook "msg" file saved as a "pdf" in stead of "msg". I realize this is a lot, but I've been tinkering with the code since Friday and keep coming up empty. Thanks in advance for any help I can get on this.
Cross posted in this forum, because I didn't know this forum existed at the time.
I'm new to this forum. I came here because I found Diane Poremsky's code called "SaveMessagesAndAttachments" and need to see if it can be tweaked to allow me to start with a defined file path and once the dialog box opens, give me the opportunity to drill down a couple folders form there to place all the files that are created. Ideally, I would like to have the Outlook "msg" file saved as a "pdf" in stead of "msg". I realize this is a lot, but I've been tinkering with the code since Friday and keep coming up empty. Thanks in advance for any help I can get on this.
Cross posted in this forum, because I didn't know this forum existed at the time.
Public Sub SaveMessagesAndAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem 'Object
Dim objAttachments As Outlook.Attachments
Dim i As Long
Dim lngCount As Long
Dim StrFile As String
Dim StrName As String
Dim strTime 'As String
Dim StrFolderPath As String
Dim FSO As Object
Dim oldName
Set FSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objOL = Outlook.Application
Set objMsg = objOL.ActiveExplorer.Selection.Item(1)
' remove illegal characters and shorten name
StrName = StripIllegalChar(objMsg.Subject)
StrName = Left(StrName, 40)
strTime = DateValue(objMsg.ReceivedTime) '& TimeValue(objMsg.ReceivedTime)
' I use this to reduce changes of duplicate names
strTime = Format(objMsg.ReceivedTime, "-hhmmss")
Debug.Print strTime
strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
Debug.Print strFolderpath
On Error Resume Next
StrFolderPath = StrFolderPath & "\Attachments\" & StrName & strTime & "\"
' create folder if doesn't exist
If Not FSO.FolderExists(StrFolderPath) Then
FSO.CreateFolder (StrFolderPath)
End If
' Save message and as html and doc file type
objMsg.SaveAs StrFolderPath & StrName & ".msg", olMsg
objMsg.SaveAs StrFolderPath & StrName & ".doc", olRTF
objMsg.SaveAs StrFolderPath & StrName & ".htm", olHTML
'save any attachments also
Set objAttachments = objMsg.Attachments
lngCount = objAttachments.Count
If lngCount > 0 Then
For i = lngCount To 1 Step -1
StrFile = objAttachments.Item(i).FileName
Debug.Print StrFile
StrFile = StrFolderPath & StrFile
objAttachments.Item(i).SaveAsFile StrFile
Next i
End If
ExitSub:
Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub