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.
Top