Outlook Rule Save Email For Text

I am having problems automatically exporting the body of a message to a text file using a script. I managed to create a script that will save the text in a file on a macro, but this will not work on the rule that I need.

My current code is as follows:

Sub SaveAsTXT()
 Dim myItem As Outlook.Inspector
 Dim objItem As Object
 Dim myFolder As Folder



 Set myItem = Application.ActiveInspector
 If Not TypeName(myItem) = "Nothing" Then

        Set myNamespace = Application.GetNamespace("MAPI")
        Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)

 Set objItem = myItem.CurrentItem
 strname = objItem.Subject
 strdate = Format(objItem.ReceivedTime, " yyyy mm dd")
 objItem.SaveAs "c:\users\philip\documents\" & strname & strdate & ".txt", olTXT
    End If

End Sub

Sorry if it looks a little dirty, I edited it countless times, trying to get it to work.

What is the code that will execute correctly when I am in an open message and run it as a macro, but it will not work correctly when I start it? As a rule, I tried to make changes to it Sub SaveAsTXT(Item as Outlook.Mailitem), but it also doesn’t work

, , , ( "Rotas" ), ?

: Office 2010 .

+4
1

.

, item as Outlook.Mailitem , . item , objItem

( ) :

Sub SaveAsTXT(myMail As Outlook.MailItem)

 Dim objItem As Object
 Dim myFolder As Folder


 If Not TypeName(myitem) = "Nothing" Then

        If myMail.Subject = "Rotas" Then

 strname = myMail.Subject
 strdate = Format(myMail.ReceivedTime, " yyyy mm dd")
 myMail.SaveAs "c:\users\philip\documents\" & strname & ".txt", olTXT
    End If


 End If

End Sub
+6

Source: https://habr.com/ru/post/1568345/


All Articles