Rules Wizard Script

  • Thread starter Thread starter Henry Stockbridge
  • Start date Start date
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
 
Don't close your text stream until after you finish writing to it, after the
For Each ... Next loop.
 
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
 
Back
Top