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?
 
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
 
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,
 
You need to set a reference to Word object model in Tools, References in the VBA editor.
 
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?
 
just choose word object that is available - it should work with office 2007 and newer, probably with older ones too.
 
Decided to reboot my machine and the macro now works.

Thanks again for your help.
 
One final request, when forwarding the e-mail would it be possible to add the original senders e-mail address as being copied in?
 
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
 
Hi, me again. am having problems when adding "oresponse.to = strSender" I get a runtime error 424 object required.
 
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.
 
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
F Outlook 2019 Forwarding Message and Keeping Unread Status Outlook VBA and Custom Forms 0
A Outlook 2019 Help with forwarding email without mentioning the previous email sender. Outlook VBA and Custom Forms 0
D Forwarding email based on the attachment file type and specific text found on the attachment file name Outlook VBA and Custom Forms 1
T Original email text not shown when replying or forwarding the email. Using Outlook 9
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
L Error when exporting Sent Mail to Excel Outlook VBA and Custom Forms 6
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
K How can I delete an e-mail from Outlook Using Outlook 1
L Help: set flag for sent mail to check if received an answer Outlook VBA and Custom Forms 2
A Macro Mail Alert Using Outlook 4
e_a_g_l_e_p_i MY Outlook 2021 changed the format of the shortcuts for mail, calendar etc. Using Outlook 10

Similar threads

Back
Top