Rules Wizard Script

H

Henry Stockbridge

Hi,

I have created a rule for incoming messages with attachments that
writes information to a text file about the date, sender, and
filename. The script runs successfully if the email message has one
(1) attachment, but throws an error ('Object variable or With block
variable not set) if the message contains more than one attachment.

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

Sub Coordinator_Emails_2(item As Outlook.MailItem)

Const ForAppending = 8

Dim fso
Dim f1
Dim ts
Dim i As Integer

Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.GetFile("c:\ReportingLog.txt")
Set ts = f1.OpenAsTextStream(ForAppending, True)

For i = 1 To item.Attachments.Count '- 1
'MsgBox item.Attachments(i).FileName

ts.Write Format(item.SentOn, "Short Date") & vbTab & item.Subject
& vbTab & item.To & vbTab & item.Attachments(i)
ts.writeblanklines (1)
ts.Close

Next i

Set ts = nothing
Set f1 = nothing
set fso = nothing

End Sub

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

Any help you can lend would be appreciated.

Henry
 
S

Sue Mosher [MVP-Outlook]

Don't close your text stream until after you finish writing to it, after the
For Each ... Next loop.
 
H

Henry Stockbridge

Don't close your text stream until after you finish writing to it, after the
For Each ... Next loop.
--
Sue Mosher, Outlook MVP
   Author of Microsoft Outlook Programming: Jumpstart
      for Administrators, Power Users, and Developers
     














- Show quoted text -

Sue,

Thanks for the tip. Works like magic!

Henry
 

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