save as a text file

F

Finalstryke

Hi,
I'm a bit new at scripting and stuff, but I'd really appreciate some
pointers on how to do a custom message rule.

All I want to do is check for the conditions, and if they're met then run a
script that simply saves the whole message as a .txt file at a location
given by a designated file path.

The nearest I could find in the help file was something like:

----------------------------------------------------------------------------
---------
Sub CustomMailMessageRule(Item As Outlook.MailItem)

Dim myItem As Inspector
Dim objItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.ActiveInspector
If Not TypeName(myItem) = "Nothing" Then
Set objItem = myItem.CurrentItem
strname = objItem.Subject
objItem.SaveAs "C:\...." & " & strname & .txt", olTXT
Else
MsgBox "There is no current active Inspector."
End If

End Sub
----------------------------------------------------------------------------
-------------------------

but even after adding in the correct filepath all I could get was the msgbox
popping up at me and telling me there was no current active inspector

help... I don't even know what an inspector is!

:)

Thanks,
Owen
 
S

Sue Mosher [MVP]

Remove all references to an Inspector, which would be an open message --
irrelevant to a script that runs as part of a rule as yours is designed to
to. The item that your code is working with is the Item object passed as an
argument to the procedure.

Sub CustomMailMessageRule(Item As Outlook.MailItem)
strname = Item.Subject
Item.SaveAs "C:\...." & " & strname & .txt", olTXT
End Sub

I didn't see any attempt to set conditions related to the content of the
message.
 
F

Finalstryke

Hi Sue,
thanks for that, it worked fine.

There were a couple of problems though.

The file was being saved as "strname.txt", and despite trying to tweak
it I couldn't get it to read as the full subject string, this wasn't
too bad since I don't nead to build a store so overwriting prevous
files isn't an issue.

Also, the formatting of the email has changed - the text gets wrapped
before the natural end of the lines - is it possible to amend this
with a script?

Thanks again,
Owen
 
S

Sue Mosher [MVP]

You have misplaced quotation marks in your original statement, which I
didn't catch. Try:

Item.SaveAs "C:\" & strname & ".txt", olTXT

To change the wrapping behavior, you'd probably have to abandon the
Item.SaveAs approach and write your own text file out line-by-line
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top