I need assistance on some code to incorporate into an Outlook rule.
When a message arrives in the inbox, a rule does the following:
1. Copies it into a specific folder
2. Runs a script file to extract the message body into a text file and then saves the text file with the date in the first line of the text body.
I need help to generate the script file please. I have two macros that I have sourced from other locartions, but I do not know how to get the date in the first line to become the name of the text file.
Any help will be appreciated. TX
Code I have:
Either one can be modified based on my needs...TX
Code: Select all
Sub SaveTXT1()
Dim FileName As Variant
Dim msg As Outlook.MailItem
' assume an email is selected
Set msg = ActiveExplorer.Selection.Item(1)
FileName = Split(msg.Body, vbCrLf)
MsgBox FileName
' save as text file
msg.SaveAs "C:\" & FileName & ".txt", olTXT
End Sub
Sub SaveTXT2(Item As Outlook.MailItem)
Dim strExportPath As String, FileName As Variant
strExportPath = "C:\"
Dim FileName As String
'FileName = strExportPath & Replace(Replace(Replace(Now & "_" & Item.EntryID & ".txt", ":", "_"), "-", "_"), " ", "_") 'Create filename and path, replace : with _, - with _ and space with _.
FileName = Split(Item.Body, vbCrLf)
Dim FileNum As Integer
FileNum = FreeFile ' next file number
Open FileName For Output As #FileNum ' creates the file if it doesn't exist
Print #FileNum, Item.Body ' write information at the end of the text file
Close #FileNum ' close the file
End Sub