Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / January 2007

Tip: Looking for answers? Try searching our database.

How do I script to change the subject line of incoming mail?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Glenn Harless - 11 Nov 2005 14:31 GMT
I wish to create a script to alter the subject line of incoming mail to
remove certain character strings.

Google has not been much help...any suggestions or guidence is appreciatied
Sue Mosher [MVP-Outlook] - 11 Nov 2005 15:18 GMT
One way is to use a  "run a script" rule, a Rules Wizard action that invokes a VBA procedure with a MailItem or MeetingItem as its parameter, then uses that item in the code:

Sub RunAScriptRuleRoutine(MyMail As MailItem)
   Dim strID As String
   Dim olNS As Outlook.NameSpace
   Dim olMail As Outlook.MailItem
   
   strID = MyMail.EntryID
   Set olNS = Application.GetNamespace("MAPI")
   Set olMail = olNS.GetItemFromID(strID)
   ' do stuff with olMail, e.g.
   olMail.SUbject  = "whatever you want the subject to be"
   olMaIl.Save
   
   Set olMail = Nothing
   Set olNS = Nothing
End Sub

See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example.

Signature

Sue Mosher, Outlook MVP
  Author of Configuring Microsoft Outlook 2003
    http://www.turtleflock.com/olconfig/index.htm
  and Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

>I wish to create a script to alter the subject line of incoming mail to
> remove certain character strings.
>
> Google has not been much help...any suggestions or guidence is appreciatied
Glenn Harless - 11 Nov 2005 17:50 GMT
Thanks Sue. I'll give it a shot
D-Man - 29 Jan 2007 16:01 GMT
Good Morning Sue,

I am new to scripting in VBA but I have done some vbs scripting. We receive
about 25,000 faxes  and they are sent to an Outlook Mailbox. The subject of
the e-mails contain the senders fax number. We would like to have a rule
change the fax number to the customers name when the e-mail arrives. I tried
your code below with the changes below but I am unable to get it to work.
Would you be so kind as to help me through this?

Sub RunAScriptRuleRoutine(MyMail As MailItem)
   Dim strID As String
   Dim olNS As Outlook.NameSpace
   Dim olMail As Outlook.MailItem
   
   strID = MyMail.EntryID
   Set olNS = Application.GetNamespace("MAPI")
   Set olMail = olNS.GetItemFromID(strID)
   ' do stuff with olMail, e.g.
   If olMail.Subject = "555-1212" Then
   olMail.Subject = "New Customer"
   olMail.Save
   End If
   
   Set olMail = Nothing
   Set olNS = Nothing
End Sub

Thanks In advance

> One way is to use a  "run a script" rule, a Rules Wizard action that invokes a VBA procedure with a MailItem or MeetingItem as its parameter, then uses that item in the code:
>
[quoted text clipped - 20 lines]
> >
> > Google has not been much help...any suggestions or guidence is appreciatied
Sue Mosher [MVP-Outlook] - 29 Jan 2007 16:26 GMT
What in particular doesn't work? Did you check the VBA basics at http://www.outlookcode.com/d/vbabasics.htm?

Signature

Sue Mosher, Outlook MVP
  Author of Configuring Microsoft Outlook 2003
    http://www.turtleflock.com/olconfig/index.htm
  and Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx
 

> Good Morning Sue,
>
[quoted text clipped - 49 lines]
>> >
>> > Google has not been much help...any suggestions or guidence is appreciatied
D-Man - 29 Jan 2007 17:06 GMT
I did go through that document. Could the problem be that if the faxes are
not going to the default inbox but rather than another user account mailbox?
Do I need to make changes in the script to reflect that?

Thanks in advance.

> What in particular doesn't work? Did you check the VBA basics at http://www.outlookcode.com/d/vbabasics.htm?
>
[quoted text clipped - 51 lines]
> >> >
> >> > Google has not been much help...any suggestions or guidence is appreciatied
Sue Mosher [MVP-Outlook] - 29 Jan 2007 19:12 GMT
The code you cited works with an Outlook rule, which means it affects only messages coming into your own mailbox. To handle items in another mailbox with Outlook code, you would have to leave a machine running 24/7 and use a different coding approach -- the MAPIFolder.Items.ItemAdd event.

Signature

Sue Mosher, Outlook MVP
  Author of Configuring Microsoft Outlook 2003
    http://www.turtleflock.com/olconfig/index.htm
  and Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx
 

>I did go through that document. Could the problem be that if the faxes are
> not going to the default inbox but rather than another user account mailbox?
[quoted text clipped - 52 lines]
>> >>
>> >> See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example.

>> >> >I wish to create a script to alter the subject line of incoming mail to
>> >> > remove certain character strings.
>> >> >
>> >> > Google has not been much help...any suggestions or guidence is appreciatied
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.