HOW DO I FORWARD AN EMAIL WITH MACRO using an email that in the body of another email

Status
Not open for further replies.

Sabastian Samuel

New Member
Outlook version
Outlook 2016 64 bit
Email Account
IMAP
I WOULD REALLY APPRECIATE IT IF SOMEONE COULD HELP ME OUT. IVE BEEN TRYING TO UNDERSTAND MACRO LANGUAGE FOR AGES AND I CANT SEEM TO GET ANYWHERE!
HERE IS WHAT I WANT TO DO. I hope this makes sense.

----

I want a macro to read every email that gets sent to my inbox.

IF the subject line begins with "Lost Property at"
THEN extract the whole body of the email as a string - string name "BODY"

SPLIT the the string at the point where "\split" is in the text

I should have these strings only now

BODY_1
BODY_2


i dont think there is a chance of \split being in the body more than once. but if it is, i would want to isolate BODY_1 and concatenate the rest together

I now want the macro to write an email:

to: BODY_1
subject
: the subject of the original email
body: BODY_2

SEND
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
you can use it either in a run a script rule or watch the folder and process it using an itemadd macro.
Outlook's Rules and Alerts: Run a Script
How to use an ItemAdd Macro


this snippet will do what you need (i think the array code is correct, but it might need tweaked)-

if lcase(item.subject) = "lost property" then
Dim BodyArray() As variant

BodyArray() = (item.body, "\split", 2)

--create new message --
Create a new Outlook message using VBA

then use this:
newMsg.to = bodyarray(1)
newMsg.body = bodyarray(2)
newMsg.send

end if
 

Sabastian Samuel

New Member
Outlook version
Outlook 2016 64 bit
Email Account
IMAP
There is an error on BodyArray() = (item.body, "\split", 2)

upload_2017-10-20_15-49-51.png
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
you need to set the item object to a message - this will use the selected message (great for testing - change it to use incoming messages later)

sub lostpropertyforward()
Set Item = application.ActiveExplorer.Selection.Item(1)
' rest of your code
end sub
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A Forward Outlook Email by Filtering using Macro Rule Outlook VBA and Custom Forms 44
W Macro to forward email Outlook VBA and Custom Forms 2
divan Macro to format email in a certain folder then forward to email address Using Outlook 3
Bering Forward selected email without the original email appended Outlook VBA and Custom Forms 0
J Automatically forward email and apply template Outlook VBA and Custom Forms 0
O Forward a email with modified body Automatically. Outlook VBA and Custom Forms 0
C How to rename subject line and forward the email Outlook VBA and Custom Forms 2
R Error when trying to forward current email item Outlook VBA and Custom Forms 7
B Forward every other email in Outlook 2013 Outlook VBA and Custom Forms 2
D Disable or hide "reply" and "reply to all" and "forward" in email from access vba Outlook VBA and Custom Forms 1
Brostin Forward a mail to the address listed in the email text Outlook VBA and Custom Forms 1
A Creating an outlook rule to forward an email with a specific message Using Outlook 1
D How to forward each email x minutes after it arrives in inbox and hasn't been moved or deleted? Using Outlook 1
mikecox Forward email to another address; not with Rules Using Outlook 3
D forward email with attachment using .oft Using Outlook 3
R Auto-create receipt from email and forward to payer Using Outlook 3
C Unable to forward email with URL Using Outlook 2
M rule to change subject, pull email addresses from body, and forward with templ Using Outlook 14
S Rule to Auto-forward/re-direct a specific incoming email to a group via BCC? Using Outlook 1
A Outlook 2010 - Want to Have All Email Reply Forward as Rich Test Using Outlook 7
P email arrows - respond and forward Using Outlook 1
B Outlook 2010 auto-forward deletes message text from forwarded email Using Outlook 7
L Forward Email and Insert Sender's Email address in body Outlook VBA and Custom Forms 3
M Forward email as insert from button Outlook VBA and Custom Forms 1
J Rule to Forward email but delay delivery 10 minutes Outlook VBA and Custom Forms 2
S forward email Outlook VBA and Custom Forms 1
C UDFs Reply vs Forward Outlook VBA and Custom Forms 2
M In Outlook Calendar remove the buttons: 'Today' and '<' (Back a day) and '>' (Forward a day) that are below the Ribbon and above the calendar display. Using Outlook 0
M Outlook macro to automate search and forward process Outlook VBA and Custom Forms 6
G Missing forward/replied icons Using Outlook 2
M VBA to auto forward message with new subject and body text Outlook VBA and Custom Forms 8
B Automatically Forward Emails and Remove/Replace All or Part of Body Outlook VBA and Custom Forms 8
M Forward Appointment as BCC with VBScript Outlook VBA and Custom Forms 7
C Don't forward duplicate Using Outlook 0
undercover_smother Automatically Forward All Sent Mail and Delete After Send Outlook VBA and Custom Forms 10
I change subject and forward without FW: Outlook VBA and Custom Forms 4
C VBA to Forward e-mails from certain address and between certain times Outlook VBA and Custom Forms 1
J Forward Action in Form Outlook VBA and Custom Forms 1
J Auto Forward - Include Attachment and change Subject depending on original sender Outlook VBA and Custom Forms 3
K add pdf to every reply or forward Outlook VBA and Custom Forms 1
N Going Forward: Using Outlook 2016 for RSS Feeds Using Outlook 2
J Forward Message after editing attachments and include edited attachments Using Outlook 5
R changing FW: on forward Outlook VBA and Custom Forms 3
Z Auto Forward Using Outlook 4
N Outlook script to forward emails based on senders' address Outlook VBA and Custom Forms 2
S Merge Emails with attachments with inbox rule to forward Using Outlook 5
B Auto Save of Attachments from Multiple Emails and forward attachments to user group Outlook VBA and Custom Forms 1
D Forward message to address from subject Outlook VBA and Custom Forms 1
J How to change From then forward message Outlook VBA and Custom Forms 1
S Reply & Forward Date in original message incorrect Using Outlook 2

Similar threads

Top