Script help - retain forwarded email body & location of script

  • Thread starter Thread starter Dawn
  • Start date Start date
Status
Not open for further replies.
D

Dawn

Hi, with the help of searching this forum (thanks, this place is amazing!) I

figured out a script that would forward a specified email when a rule finds

emails that meet certain criteria. It works really well, but I still have

two questions.

1) I am not sure I've saved the script in an appropriate location. I

really like this script and imagine I will be able to use variants of it for

a number of situations, so I want to be sure I'm saving it appropriately to

do so. The location I picked was based on a post, but it may have just been

telling a person where to save a script to test it temporarily?

In the Visual Basic editor, I have the Projects explorer window open, which

gave me a folder called Microsoft Office Outlook Objects. In this folder is

something called ThisOutlookSession. If I click this, a VB window is opened,

and I have my code in there. I am hoping if I put in another similar sub

into the same window, I will then be able to pick it to be used in another

rule.

2) the script works great, except that it would be even better if it

retained the body of the email that fired the rule. This code produces an

email that retains just the subject line, but the body of the email is blank

except for my new text. Code is below. Thanks in advance for any help!

Sub RunAScriptRuleRoutine(MyMail As MailItem)

Dim strID As String

Dim olNS As Outlook.NameSpace

Dim msg As Outlook.MailItem

Dim fwd As Outlook.MailItem

strID = MyMail.EntryID

Set olNS = Application.GetNamespace("MAPI")

Set msg = olNS.GetItemFromID(strID)

Set fwd = msg.Forward

With fwd

> To = "jdoe@yahoo.com"

> Subject = fwd.Subject & " -- MY TEXT HERE"

> HTMLBody = "Here is my email message."

> Send

End With

Set msg = Nothing

Set olNS = Nothing

End Sub
 
1) That's a fine place. You can also add a new module to hold just your rule

scripts if you prefer. You can copy and paste the one you have to create the

next one, changing the name of the procedure, of course.

2) This statement replaces the existing body with the text on the right side

of the equals sign:

> HTMLBody = "Here is my email message."

Take it out, and the forward message will be unchanged.

Sue Mosher

"Dawn" <dawn@NOSPAMstofoco.com> wrote in message

news:C4FBB8F3-5476-4B4E-9D81-1F3271F8AD9B@microsoft.com...
> Hi, with the help of searching this forum (thanks, this place is amazing!)
> I
> figured out a script that would forward a specified email when a rule
> finds
> emails that meet certain criteria. It works really well, but I still have
> two questions.

> 1) I am not sure I've saved the script in an appropriate location. I
> really like this script and imagine I will be able to use variants of it
> for
> a number of situations, so I want to be sure I'm saving it appropriately
> to
> do so. The location I picked was based on a post, but it may have just
> been
> telling a person where to save a script to test it temporarily?

> In the Visual Basic editor, I have the Projects explorer window open,
> which
> gave me a folder called Microsoft Office Outlook Objects. In this folder
> is
> something called ThisOutlookSession. If I click this, a VB window is
> opened,
> and I have my code in there. I am hoping if I put in another similar sub
> into the same window, I will then be able to pick it to be used in another
> rule.

> 2) the script works great, except that it would be even better if it
> retained the body of the email that fired the rule. This code produces an
> email that retains just the subject line, but the body of the email is
> blank
> except for my new text. Code is below. Thanks in advance for any help!

> Sub RunAScriptRuleRoutine(MyMail As MailItem)
> Dim strID As String
> Dim olNS As Outlook.NameSpace
> Dim msg As Outlook.MailItem
> Dim fwd As Outlook.MailItem

> strID = MyMail.EntryID
> Set olNS = Application.GetNamespace("MAPI")
> Set msg = olNS.GetItemFromID(strID)
> Set fwd = msg.Forward
> With fwd
> .To = "jdoe@yahoo.com"
> .Subject = fwd.Subject & " -- MY TEXT HERE"
> .HTMLBody = "Here is my email message."
> .Send
> End With

> Set msg = Nothing
> Set olNS = Nothing
> End Sub
>
 
Thanks Sue! Can you think of a way to both of a way to retain the original

body of the email, along with my new text that I'm trying to put in? I can

always just go find the original email by using the subject line, but it

would be great if I could save that step. Similar to how the subject line is

retained, along with my additional text. Would something like this work?

> .HTMLBody = "Here is my email message." & fwd.Body

Cheers,

Dawn

"Sue Mosher [MVP]" wrote:


> 1) That's a fine place. You can also add a new module to hold just your rule
> scripts if you prefer. You can copy and paste the one you have to create the
> next one, changing the name of the procedure, of course.

> 2) This statement replaces the existing body with the text on the right side
> of the equals sign:

> .HTMLBody = "Here is my email message."

> Take it out, and the forward message will be unchanged.

> > Sue Mosher
> > >

> "Dawn" <dawn@NOSPAMstofoco.com> wrote in message
> news:C4FBB8F3-5476-4B4E-9D81-1F3271F8AD9B@microsoft.com...
> > Hi, with the help of searching this forum (thanks, this place is amazing!)
> > I
> > figured out a script that would forward a specified email when a rule
> > finds
> > emails that meet certain criteria. It works really well, but I still have
> > two questions.
> > 1) I am not sure I've saved the script in an appropriate location. I
> > really like this script and imagine I will be able to use variants of it
> > for
> > a number of situations, so I want to be sure I'm saving it appropriately
> > to
> > do so. The location I picked was based on a post, but it may have just
> > been
> > telling a person where to save a script to test it temporarily?
> > In the Visual Basic editor, I have the Projects explorer window open,
> > which
> > gave me a folder called Microsoft Office Outlook Objects. In this folder
> > is
> > something called ThisOutlookSession. If I click this, a VB window is
> > opened,
> > and I have my code in there. I am hoping if I put in another similar sub
> > into the same window, I will then be able to pick it to be used in another
> > rule.
> > 2) the script works great, except that it would be even better if it
> > retained the body of the email that fired the rule. This code produces an
> > email that retains just the subject line, but the body of the email is
> > blank
> > except for my new text. Code is below. Thanks in advance for any help!
> > Sub RunAScriptRuleRoutine(MyMail As MailItem)
> > Dim strID As String
> > Dim olNS As Outlook.NameSpace
> > Dim msg As Outlook.MailItem
> > Dim fwd As Outlook.MailItem
> > strID = MyMail.EntryID
> > Set olNS = Application.GetNamespace("MAPI")
> > Set msg = olNS.GetItemFromID(strID)
> > Set fwd = msg.Forward
> > With fwd
> > .To = "jdoe@yahoo.com"
> > .Subject = fwd.Subject & " -- MY TEXT HERE"
> > .HTMLBody = "Here is my email message."
> > .Send
> > End With
> > Set msg = Nothing
> > Set olNS = Nothing
> > End Sub
> >


>
 
Sorry, it wasn't clear to me from your earlier posts that you needed to add

information to the forwarded message. If you don't care about formatting,

you can use code like what you propose. If you want to retain the full

formatting of the item, you need to work with fwd.HTMLBody not fwd.Body, but

you can't just use simple concatenation. You would need to insert the new

text inside the HTMLBody content, with proper HTML tagging (as in a web

page); that just takes some text parsing.

You may have other options as well, depending on your Outlook version and

the email editor.

Sue Mosher

"Dawn" <dawn@NOSPAMstofoco.com> wrote in message

news:3F707559-62CE-4543-BB24-4912C41A6A09@microsoft.com...
> Thanks Sue! Can you think of a way to both of a way to retain the
> original
> body of the email, along with my new text that I'm trying to put in? I
> can
> always just go find the original email by using the subject line, but it
> would be great if I could save that step. Similar to how the subject line
> is
> retained, along with my additional text. Would something like this work?

> .HTMLBody = "Here is my email message." & fwd.Body

> Cheers,
> Dawn

> "Sue Mosher [MVP]" wrote:
>
> > 1) That's a fine place. You can also add a new module to hold just your
> > rule
> > scripts if you prefer. You can copy and paste the one you have to create
> > the
> > next one, changing the name of the procedure, of course.
>

>> 2) This statement replaces the existing body with the text on the right
> > side
> > of the equals sign:
>

>> .HTMLBody = "Here is my email message."
>

>> Take it out, and the forward message will be unchanged.
>

>> "Dawn" <dawn@NOSPAMstofoco.com> wrote in message
> > news:C4FBB8F3-5476-4B4E-9D81-1F3271F8AD9B@microsoft.com...
> > > Hi, with the help of searching this forum (thanks, this place is
> > > amazing!)
> > > I
> > > figured out a script that would forward a specified email when a rule
> > > finds
> > > emails that meet certain criteria. It works really well, but I still
> > > have
> > > two questions.
> >> > 1) I am not sure I've saved the script in an appropriate location. I
> > > really like this script and imagine I will be able to use variants of
> > > it
> > > for
> > > a number of situations, so I want to be sure I'm saving it
> > > appropriately
> > > to
> > > do so. The location I picked was based on a post, but it may have just
> > > been
> > > telling a person where to save a script to test it temporarily?
> >> > In the Visual Basic editor, I have the Projects explorer window open,
> > > which
> > > gave me a folder called Microsoft Office Outlook Objects. In this
> > > folder
> > > is
> > > something called ThisOutlookSession. If I click this, a VB window is
> > > opened,
> > > and I have my code in there. I am hoping if I put in another similar
> > > sub
> > > into the same window, I will then be able to pick it to be used in
> > > another
> > > rule.
> >> > 2) the script works great, except that it would be even better if it
> > > retained the body of the email that fired the rule. This code produces
> > > an
> > > email that retains just the subject line, but the body of the email is
> > > blank
> > > except for my new text. Code is below. Thanks in advance for any
> > > help!
> >> > Sub RunAScriptRuleRoutine(MyMail As MailItem)
> > > Dim strID As String
> > > Dim olNS As Outlook.NameSpace
> > > Dim msg As Outlook.MailItem
> > > Dim fwd As Outlook.MailItem
> >> > strID = MyMail.EntryID
> > > Set olNS = Application.GetNamespace("MAPI")
> > > Set msg = olNS.GetItemFromID(strID)
> > > Set fwd = msg.Forward
> > > With fwd
> > > .To = "jdoe@yahoo.com"
> > > .Subject = fwd.Subject & " -- MY TEXT HERE"
> > > .HTMLBody = "Here is my email message."
> > > .Send
> > > End With
> >> > Set msg = Nothing
> > > Set olNS = Nothing
> > > End Sub
> > >

>

>
>>
 
Thanks! I don't know how to do HTML tagging, can you point me in right

direction? (and sorry if I'm asking for the sun moon and stars, I really

don't know if what I'm asking is complicated or not!) The end result I'm

looking for is an email, that would be as if I had hit the "forward" button

in outlook, then typed my message ("my text here") and hit send. I'm wanting

my additional text to appear as the first thing in the email string.

"Sue Mosher [MVP]" wrote:


> Sorry, it wasn't clear to me from your earlier posts that you needed to add
> information to the forwarded message. If you don't care about formatting,
> you can use code like what you propose. If you want to retain the full
> formatting of the item, you need to work with fwd.HTMLBody not fwd.Body, but
> you can't just use simple concatenation. You would need to insert the new
> text inside the HTMLBody content, with proper HTML tagging (as in a web
> page); that just takes some text parsing.

> You may have other options as well, depending on your Outlook version and
> the email editor.

> > Sue Mosher
> > >

> "Dawn" <dawn@NOSPAMstofoco.com> wrote in message
> news:3F707559-62CE-4543-BB24-4912C41A6A09@microsoft.com...
> > Thanks Sue! Can you think of a way to both of a way to retain the
> > original
> > body of the email, along with my new text that I'm trying to put in? I
> > can
> > always just go find the original email by using the subject line, but it
> > would be great if I could save that step. Similar to how the subject line
> > is
> > retained, along with my additional text. Would something like this work?
> > .HTMLBody = "Here is my email message." & fwd.Body
> > Cheers,
> > Dawn
> > "Sue Mosher [MVP]" wrote:
> >
> >> 1) That's a fine place. You can also add a new module to hold just your
> >> rule
> >> scripts if you prefer. You can copy and paste the one you have to create
> >> the
> >> next one, changing the name of the procedure, of course.
> >
> >> 2) This statement replaces the existing body with the text on the right
> >> side
> >> of the equals sign:
> >
> >> .HTMLBody = "Here is my email message."
> >
> >> Take it out, and the forward message will be unchanged.
> >
> >> "Dawn" <dawn@NOSPAMstofoco.com> wrote in message
> >> news:C4FBB8F3-5476-4B4E-9D81-1F3271F8AD9B@microsoft.com...
> >> > Hi, with the help of searching this forum (thanks, this place is
> >> > amazing!)
> >> > I
> >> > figured out a script that would forward a specified email when a rule
> >> > finds
> >> > emails that meet certain criteria. It works really well, but I still
> >> > have
> >> > two questions.
> >> >> > 1) I am not sure I've saved the script in an appropriate location. I
> >> > really like this script and imagine I will be able to use variants of
> >> > it
> >> > for
> >> > a number of situations, so I want to be sure I'm saving it
> >> > appropriately
> >> > to
> >> > do so. The location I picked was based on a post, but it may have just
> >> > been
> >> > telling a person where to save a script to test it temporarily?
> >> >> > In the Visual Basic editor, I have the Projects explorer window open,
> >> > which
> >> > gave me a folder called Microsoft Office Outlook Objects. In this
> >> > folder
> >> > is
> >> > something called ThisOutlookSession. If I click this, a VB window is
> >> > opened,
> >> > and I have my code in there. I am hoping if I put in another similar
> >> > sub
> >> > into the same window, I will then be able to pick it to be used in
> >> > another
> >> > rule.
> >> >> > 2) the script works great, except that it would be even better if it
> >> > retained the body of the email that fired the rule. This code produces
> >> > an
> >> > email that retains just the subject line, but the body of the email is
> >> > blank
> >> > except for my new text. Code is below. Thanks in advance for any
> >> > help!
> >> >> > Sub RunAScriptRuleRoutine(MyMail As MailItem)
> >> > Dim strID As String
> >> > Dim olNS As Outlook.NameSpace
> >> > Dim msg As Outlook.MailItem
> >> > Dim fwd As Outlook.MailItem
> >> >> > strID = MyMail.EntryID
> >> > Set olNS = Application.GetNamespace("MAPI")
> >> > Set msg = olNS.GetItemFromID(strID)
> >> > Set fwd = msg.Forward
> >> > With fwd
> >> > .To = "jdoe@yahoo.com"
> >> > .Subject = fwd.Subject & " -- MY TEXT HERE"
> >> > .HTMLBody = "Here is my email message."
> >> > .Send
> >> > End With
> >> >> > Set msg = Nothing
> >> > Set olNS = Nothing
> >> > End Sub
> >> >
> >
> >>


>
 
Sorry, but I'm not equipped to do an HTML tutorial; there are plenty of

those on the web. You'll get a good start if you just look at the source of

any HTML-format message.

In the meantime, if you don't care about formatting, you can just use this:

> Body = "Here is my email message." & vbCrLf & fwd.Body

Sue Mosher

"Dawn" <dawn@NOSPAMstofoco.com> wrote in message

news:D4F88ED9-11E7-46D6-A71A-C0DAFDC6691B@microsoft.com...
> Thanks! I don't know how to do HTML tagging, can you point me in right
> direction? (and sorry if I'm asking for the sun moon and stars, I really
> don't know if what I'm asking is complicated or not!) The end result I'm
> looking for is an email, that would be as if I had hit the "forward"
> button
> in outlook, then typed my message ("my text here") and hit send. I'm
> wanting
> my additional text to appear as the first thing in the email string.

> "Sue Mosher [MVP]" wrote:
>
> > Sorry, it wasn't clear to me from your earlier posts that you needed to
> > add
> > information to the forwarded message. If you don't care about formatting,
> > you can use code like what you propose. If you want to retain the full
> > formatting of the item, you need to work with fwd.HTMLBody not fwd.Body,
> > but
> > you can't just use simple concatenation. You would need to insert the new
> > text inside the HTMLBody content, with proper HTML tagging (as in a web
> > page); that just takes some text parsing.
>

>> You may have other options as well, depending on your Outlook version and
> > the email editor.
>

>> "Dawn" <dawn@NOSPAMstofoco.com> wrote in message
> > news:3F707559-62CE-4543-BB24-4912C41A6A09@microsoft.com...
> > > Thanks Sue! Can you think of a way to both of a way to retain the
> > > original
> > > body of the email, along with my new text that I'm trying to put in? I
> > > can
> > > always just go find the original email by using the subject line, but
> > > it
> > > would be great if I could save that step. Similar to how the subject
> > > line
> > > is
> > > retained, along with my additional text. Would something like this
> > > work?
> >> > .HTMLBody = "Here is my email message." & fwd.Body
> >> > Cheers,
> > > Dawn
> >>>>> > "Sue Mosher [MVP]" wrote:
> >> >> 1) That's a fine place. You can also add a new module to hold just
> > >> your
> > >> rule
> > >> scripts if you prefer. You can copy and paste the one you have to
> > >> create
> > >> the
> > >> next one, changing the name of the procedure, of course.
> > >
>> >> 2) This statement replaces the existing body with the text on the
> > >> right
> > >> side
> > >> of the equals sign:
> > >
>> >> .HTMLBody = "Here is my email message."
> > >
>> >> Take it out, and the forward message will be unchanged.
> > >
>> >> "Dawn" <dawn@NOSPAMstofoco.com> wrote in message
> > >> news:C4FBB8F3-5476-4B4E-9D81-1F3271F8AD9B@microsoft.com...
> > >> > Hi, with the help of searching this forum (thanks, this place is
> > >> > amazing!)
> > >> > I
> > >> > figured out a script that would forward a specified email when a
> > >> > rule
> > >> > finds
> > >> > emails that meet certain criteria. It works really well, but I
> > >> > still
> > >> > have
> > >> > two questions.
> > >>> >> > 1) I am not sure I've saved the script in an appropriate location.
> > >> > I
> > >> > really like this script and imagine I will be able to use variants
> > >> > of
> > >> > it
> > >> > for
> > >> > a number of situations, so I want to be sure I'm saving it
> > >> > appropriately
> > >> > to
> > >> > do so. The location I picked was based on a post, but it may have
> > >> > just
> > >> > been
> > >> > telling a person where to save a script to test it temporarily?
> > >>> >> > In the Visual Basic editor, I have the Projects explorer window
> > >> > open,
> > >> > which
> > >> > gave me a folder called Microsoft Office Outlook Objects. In this
> > >> > folder
> > >> > is
> > >> > something called ThisOutlookSession. If I click this, a VB window
> > >> > is
> > >> > opened,
> > >> > and I have my code in there. I am hoping if I put in another
> > >> > similar
> > >> > sub
> > >> > into the same window, I will then be able to pick it to be used in
> > >> > another
> > >> > rule.
> > >>> >> > 2) the script works great, except that it would be even better if
> > >> > it
> > >> > retained the body of the email that fired the rule. This code
> > >> > produces
> > >> > an
> > >> > email that retains just the subject line, but the body of the email
> > >> > is
> > >> > blank
> > >> > except for my new text. Code is below. Thanks in advance for any
> > >> > help!
> > >>> >> > Sub RunAScriptRuleRoutine(MyMail As MailItem)
> > >> > Dim strID As String
> > >> > Dim olNS As Outlook.NameSpace
> > >> > Dim msg As Outlook.MailItem
> > >> > Dim fwd As Outlook.MailItem
> > >>> >> > strID = MyMail.EntryID
> > >> > Set olNS = Application.GetNamespace("MAPI")
> > >> > Set msg = olNS.GetItemFromID(strID)
> > >> > Set fwd = msg.Forward
> > >> > With fwd
> > >> > .To = "jdoe@yahoo.com"
> > >> > .Subject = fwd.Subject & " -- MY TEXT HERE"
> > >> > .HTMLBody = "Here is my email message."
> > >> > .Send
> > >> > End With
> > >>> >> > Set msg = Nothing
> > >> > Set olNS = Nothing
> > >> > End Sub
> > >>> >
>> >
>> >>

>

>
>>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
FryW Need help modifying a VBA script for in coming emails to auto set custom reminder time Outlook VBA and Custom Forms 0
L Need help modifying a VBA script for emails stuck in Outbox Outlook VBA and Custom Forms 6
D Need Help with Script. Keep getting Runtime Error 438 BCM (Business Contact Manager) 4
R VB Script Help Using Outlook 2
R Script for simplifying spam control Outlook VBA and Custom Forms 7
J Outlook Rules VBA Run a Script - Multiple Rules Outlook VBA and Custom Forms 0
N Outlook 2021 'Run Script" Rules? Outlook VBA and Custom Forms 4
K Run a script rule to auto 'send again' on undeliverable emails? Outlook VBA and Custom Forms 1
W Designer Form 2013 and Script ? how ? Outlook VBA and Custom Forms 1
G print attachment straight away; working script edit not working Outlook VBA and Custom Forms 0
G Save attachment run a script rule Outlook VBA and Custom Forms 0
G Script does not exist Outlook VBA and Custom Forms 0
G Trigger script without restaring outlook Outlook VBA and Custom Forms 7
A VBA Script - Print Date between first email in Category X and last email in Category Y Outlook VBA and Custom Forms 3
L Modifying VBA script to delay running macro Outlook VBA and Custom Forms 3
L VB script only runs manually Outlook VBA and Custom Forms 5
E Having some trouble with a run-a-script rule (moving mail based on file type) Outlook VBA and Custom Forms 5
D.Moore VB script to Digitaly Sign newly created outlook message Outlook VBA and Custom Forms 2
Aussie Rules Run a Script on an Incoming Email OK and then the Email reverts Outlook VBA and Custom Forms 0
D.Moore VBA script fail after Office 365 update Using Outlook 8
M Outlook 2013 Script Assistance - Save Opened Link with Subject Added Outlook VBA and Custom Forms 1
F Script for zip file attachment Outlook VBA and Custom Forms 1
S Change VBA script to send HTML email instead of text Outlook VBA and Custom Forms 3
Y Outlook 2013 Run A Script Outlook VBA and Custom Forms 4
Z Script to set account? Using Outlook 0
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
N VBA Script to Open highlighted e-mail and Edit Message Outlook VBA and Custom Forms 5
B Outlook rule run a Script doesn't work Outlook VBA and Custom Forms 1
J Calling a Public sub-routine from the script editor via VB script Outlook VBA and Custom Forms 4
K Outlook Archive to PST Files by Date Range VBA Script? Outlook VBA and Custom Forms 1
Peter H Williams Enable script containing VBA Outlook VBA and Custom Forms 12
H VB script in outlook form doesn't work anymore Outlook VBA and Custom Forms 2
A Script to fetch data from mails in restricted collection and sending them to excel Using Outlook 1
B Wanting to run a script that will filter any body that has a russian link in it. Outlook VBA and Custom Forms 5
Bri the Tech Guy Registry Tweak to make "Run a Script" Action Available Outlook VBA and Custom Forms 2
V VB script code to save a specific email attachment from a given email Outlook VBA and Custom Forms 14
Bri the Tech Guy Run Script rule not running for newly arriving messages Outlook VBA and Custom Forms 25
M Subject Line Automation - Trigger Script Delayed Outlook VBA and Custom Forms 2
Q Script to create a pst file for Archiving Using Outlook 1
Vijay Error in rule- Run a script Using Outlook 1
R VBA Script Quick Parts Using Outlook 1
Vijay Run script doesn't work in outlook Using Outlook 1
Q VBA Script to move item in secondary mailbox Outlook VBA and Custom Forms 2
Diane Poremsky Run a Script Rule: Send a New Message when a Message Arrives Using Outlook 2
F Avoid sending duplicate using Outlook script Outlook VBA and Custom Forms 2
oliv- How to Run a Script IN AN ADDIN with Outlook's Rules and Alerts Outlook VBA and Custom Forms 2
L Run a Script Rule doesn't work Using Outlook 5
N Outlook script to forward emails based on senders' address Outlook VBA and Custom Forms 2
S using script rule to save attachments on arrival Outlook 2010 Outlook VBA and Custom Forms 9
X Outlook script to run excel data Outlook VBA and Custom Forms 1

Similar threads

Back
Top