Forwarding E-Mail

Status
Not open for further replies.

WorkMC

Member
Outlook version
Outlook 2010 32 bit
Email Account
I receive lots of e-mails with attachments, I need to forward these e-mails on but before I do so, I need to remove the attachment (there is usually only one) and below the body of the e-mail where the From, Sent, To and subject I need to enter a message which includes the name of the file removed. Something like "******* testfile1.xls removed *********". Currently I'm doing this manually but the process takes ages especially if the file names are long,

Despite searching many posts I cannot find anything that I can use, can anyone help?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
i have a lot of samples that get you close, put them together and you've got a macro that works... I'm assuming you don't need to do this for all forwards, just specific ones...


This macro shows how to write the attachment name to the body: Copy attachment names when replying since you are going to manually choose to forward, you just need the code that does this, not the entire macro. That would be everything between Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean) and End sub.

Change the name and add a dim
Public Sub RemoveForward()
Dim oItem As MailItem

after the dim's add
Set oItem = Application.ActiveExplorer.Selection.item(1)

Will it be the only attachment? if so, remove the if/end if lines otherwise change the for each attachment to look for the extension. if it's always only one attachment, remove strAtt & - change the text formatting as needed.
For Each oAtt In oItem.Attachments
If right(oAtt.filename, 4) = "xlxs" Then
strAtt = strAtt & "<<" & oAtt.FileName & ">> "
End If
Next oAtt

Change reply in Set oResponse = oItem.Reply to olForward.

Add this before the set oitem = nothing to delete the attachment
For Each oAtt In oResponse.Attachments
oAtt.Delete
Next oAtt
 

WorkMC

Member
Outlook version
Outlook 2010 32 bit
Email Account
Thanks or your help.

When trying to run the code I get a compile error "User-defined type not defined" which seems to effect these two lines

Dim olDocument As Word.Document
Dim olSelection As Word.Selection

If I've read your instructions correctly I need to click on the e-mail that is being forwarded in the inbox and then run the macro?

As you can probably gather I'm totally new to this code stuff,
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You need to set a reference to Word object model in Tools, References in the VBA editor.
 

WorkMC

Member
Outlook version
Outlook 2010 32 bit
Email Account
I've discovered a problem. On installing the code another machine I've found that Microsoft Word 15.0 Object Library does not work, it only shows 14.0

Is there a work around for the older version?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
just choose word object that is available - it should work with office 2007 and newer, probably with older ones too.
 

WorkMC

Member
Outlook version
Outlook 2010 32 bit
Email Account
Decided to reboot my machine and the macro now works.

Thanks again for your help.
 

WorkMC

Member
Outlook version
Outlook 2010 32 bit
Email Account
One final request, when forwarding the e-mail would it be possible to add the original senders e-mail address as being copied in?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Sure...
after set oItem....
strSender = oItem.senderemailaddress

the after you create the oResponse

oresponse.to = strSender ' or .cc


if you add more than one address, use

oresponse.recipients.add (strsender)
oresponse.recipients.type = olcc
 

WorkMC

Member
Outlook version
Outlook 2010 32 bit
Email Account
Hi, me again. am having problems when adding "oresponse.to = strSender" I get a runtime error 424 object required.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
oops - when i did it, i got the object variables from the first link, that uses oResponse. You need to use oMsg instead of oresponse. Sorry about that.
 

WorkMC

Member
Outlook version
Outlook 2010 32 bit
Email Account
Brilliant, macro is working well.

I may have other questions in the future, but in the meantime thanks.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A How to change message format while forwarding a mail Outlook VBA and Custom Forms 1
A Automatic forwarding to different people on a rotational basis Using Outlook 2
R Auto Forwarding with different "From" Outlook VBA and Custom Forms 0
P Forwarding emails issue with special characters replacing text body Using Outlook 1
S Customize the autocolor font choices for replying/forwarding messages Outlook VBA and Custom Forms 2
R Retain Original Message When Forwarding With Macro Outlook VBA and Custom Forms 3
D Keep Original html body when forwarding an email Outlook VBA and Custom Forms 7
I Forwarding attachments in email received Outlook VBA and Custom Forms 3
A Forwarding email and replacing body Outlook VBA and Custom Forms 1
D VBA to edit body of incoming email and forwarding it Outlook VBA and Custom Forms 11
M VBA Rule for removing all body but hyperlink then forwarding Outlook VBA and Custom Forms 9
G VBA/Macro to remove page colour when replying or forwarding email Outlook VBA and Custom Forms 2
D VBA Code to strip Subject Line when replying or forwarding Using Outlook 3
N Auto-forwarding an Email received from a specific Email address After slight modifications Using Outlook 4
R Forwarding and keeping Original intact Using Outlook 3
J Creating a URL from a message body excerpt before forwarding Using Outlook 2
J Outlook Rule - Create Link in Forwarding Message Outlook VBA and Custom Forms 2
E Contact's Notes field not transferring when forwarding vCard Using Outlook 6
J Meeting Invites Go Blank When Forwarding or Accepting Using Outlook 2
D Forwarding Exchange Email without meeting updates Using Outlook 1
A Emails automatically forwarding but no rule to turn off Using Outlook 2
T Adding text to forwarding rules in Outlook 2010 Using Outlook 1
T Adding tex to forwarding rules in Outlook 2010 Exchange Server Administration 1
L Forwarding an expiring message Using Outlook 0
T To: and Cc: not displaying when forwarding/replying to .eml files Using Outlook 4
V Reply Arrow Icon appears when both Replying or Forwarding Using Outlook 3
C forwarding from 365 to hotmail account? Using Outlook 1
F VB Script, remove text from subject line when forwarding Using Outlook 22
C Forwarding Outlook 2003 calendar items Using Outlook 1
B Outlook 2003 randomly not auto forwarding Using Outlook 0
M Forwarding vCard prompts Send As (From field) on Contacts that were moved Using Outlook 6
B OL2010 - signatures while forwarding tasks or appointments Using Outlook 2
D Private messages not forwarding by rule? Outlook 2007 Using Outlook 1
T [outlook-users] e masil forwarding Using Outlook 2
A Font size increases when forwarding emails Using Outlook 1
A Forwarding recurring appointment/meeting Using Outlook 2
P Forwarding Email With Encrypted Attachment Exchange Server Administration 1
A How do I move a message to a folder after forwarding ? Outlook VBA and Custom Forms 6
V Remove old recipients before forwarding Outlook VBA and Custom Forms 1
V Re: Email Forwarding Outlook VBA and Custom Forms 1
N Please advise code received new mail Using Outlook 0
M Outlook 2010 How could I globally redesign an outlook template form/region/inspector template used to display mail lists or an individual mails? Outlook VBA and Custom Forms 0
A How to stop user form from disapearing once mail window is closed? Outlook VBA and Custom Forms 0
M Outlook, send to > mail recipient - results in plain text email Using Outlook 1
R How to Sync *all* Google Workspace Mail Folders with Outlook 2019 (MS365) Using Outlook 3
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
E Having some trouble with a run-a-script rule (moving mail based on file type) Outlook VBA and Custom Forms 5
S Outlook email to configure setup for each mail Outlook VBA and Custom Forms 1
L Correct E-Mail Pulling Wrong Mail Using Outlook 5
S Outlook mail adressing stops after first match in GAL Using Outlook 0

Similar threads

Top