WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Rules Wizard Script

 
   Home -> Office -> Programming VBA RSS
Next:  Displaying temporary messages in Outlook  
Author Message
Henry Stockbridge

External


Since: Jun 20, 2008
Posts: 9



(Msg. 1) Posted: Fri Aug 29, 2008 9:49 am
Post subject: Rules Wizard Script
Archived from groups: microsoft>public>outlook>program_vba (more info?)

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
Back to top
Login to vote
Sue Mosher [MVP-Outlook]

External


Since: Jun 18, 2004
Posts: 613



(Msg. 2) Posted: Fri Aug 29, 2008 11:16 am
Post subject: RE: Rules Wizard Script [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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
http://www.outlookcode.com/jumpstart.aspx



"Henry Stockbridge" wrote:

> 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
>
Back to top
Login to vote
Henry Stockbridge

External


Since: Jun 20, 2008
Posts: 9



(Msg. 3) Posted: Fri Aug 29, 2008 12:01 pm
Post subject: Re: Rules Wizard Script [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Aug 29, 1:16 pm, Sue Mosher [MVP-Outlook] <sue... RemoveThis @outlookcode.com>
wrote:
> 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
>      http://www.outlookcode.com/jumpstart.aspx
>
>
>
> "Henry Stockbridge" wrote:
> > 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- Hide quoted text -
>
> - Show quoted text -

Sue,

Thanks for the tip. Works like magic!

Henry
Back to top
Login to vote
Display posts from previous:   
       Home -> Office -> Programming VBA All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows XP
 Windows Vista
 Windows Other
  Office
 Office Other
 Security
 WinRAR
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET