save as a text file

  • Thread starter Thread starter Finalstryke
  • Start date Start date
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
 
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.
 
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
 
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
 
I'm trying to save the body of an email that MS Outlook receives as a Text File Using VB/Macros, if anyone knows how to do this, I'd really apreciate this.

I can do it, but it puts up a User Warning that a program is trying to access the address book (or similar).

I've got around this guard on the item.send method, but can't get around this stupid thing with the text save.

Currently I use this:
==================================================
Private Sub PRS(MyMail As MailItem)
Set fso = CreateObject("Scripting.FileSystemObject")
Set aFile = fso.CreateTextFile(strTarget & "C:\PRS\REALLY_PAR.txt", True)
parastring = MyMail.Body

aFile.WriteLine (parastring)
aFile.Close

Set fso = Nothing
Set aFile = Nothing

End Sub

=====================================================

Which I ripped off the internet at some point.

I need to do this without the user being warned of the program acting in this way. I realise there are reasons for this warning, but since this script is acting on a client PC, and is internally stored, not from a third party, this is not neccessary here.

Any ideas?

-Thanks,

-Andy.
 
Back
Top