Mister H
09-29-2011, 08:08 AM
Hi All:
I am wondering if it is possible to include the value from an attached Excel File in the the filename. Here is the code I am currently trying to revise to include the value (it is numerical if that matters) of:
Cell G3 on the worksheet titled Journal
Sub Save_Emails_As_MSG_Files()
On Error GoTo ErrorHandler
Dim i As Long
Dim folder As Outlook.MAPIFolder
Dim itm As Object
Dim Msg As Outlook.MailItem
Dim msgAttachments As Outlook.Attachments
Dim msgAttach As Outlook.Attachment
Dim xlwkbk As Excel.Workbook
Dim xlwksht As Excel.Worksheet
Dim fileName As String
Set folder = Outlook.Session.GetDefaultFolder(olFolderInbox).Folders("Completed")
If folder Is Nothing Then GoTo ProgramExit
For i = folder.Items.Count To 1 Step -1
If TypeName(folder.Items(i)) = "MailItem" Then
Set Msg = folder.Items(i)
Set msgAttachments = Msg.Attachments
Msg.SaveAs "C:\COMPLETED\" & Msg.Subject & ".msg"
Msg.Move Outlook.Session.GetDefaultFolder(olFolderDeletedItems)
End If
Next i
ProgramExit:
Set xl = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Msg.SaveAs "C:\COMPLETED\" & Msg.Subject & Value(Journal!G3)" & .msg"
Any assistance or redirection would be GREATLY appreciated.
THANKS,
Have a GREAT day,
Mark
I am wondering if it is possible to include the value from an attached Excel File in the the filename. Here is the code I am currently trying to revise to include the value (it is numerical if that matters) of:
Cell G3 on the worksheet titled Journal
Sub Save_Emails_As_MSG_Files()
On Error GoTo ErrorHandler
Dim i As Long
Dim folder As Outlook.MAPIFolder
Dim itm As Object
Dim Msg As Outlook.MailItem
Dim msgAttachments As Outlook.Attachments
Dim msgAttach As Outlook.Attachment
Dim xlwkbk As Excel.Workbook
Dim xlwksht As Excel.Worksheet
Dim fileName As String
Set folder = Outlook.Session.GetDefaultFolder(olFolderInbox).Folders("Completed")
If folder Is Nothing Then GoTo ProgramExit
For i = folder.Items.Count To 1 Step -1
If TypeName(folder.Items(i)) = "MailItem" Then
Set Msg = folder.Items(i)
Set msgAttachments = Msg.Attachments
Msg.SaveAs "C:\COMPLETED\" & Msg.Subject & ".msg"
Msg.Move Outlook.Session.GetDefaultFolder(olFolderDeletedItems)
End If
Next i
ProgramExit:
Set xl = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub
Msg.SaveAs "C:\COMPLETED\" & Msg.Subject & Value(Journal!G3)" & .msg"
Any assistance or redirection would be GREATLY appreciated.
THANKS,
Have a GREAT day,
Mark