Capture "forward event" ?

Outlook version
Outlook 2007
Email Account
Exchange Server
I'd like to use VBA which triggers when "forward" is chosen. All the code I've seen is how to *initiate* a forwarding. That's not my target. Rather, I'm trying to capture when forward has just been chosen.

I may be wanting code for "OnForwarding" (a made-up word) or possibly MailItem.Forward Event
(http://msdn.microsoft.com/en-us/library/office/ff862702(v=office.15).aspx)

So I'm looking to trigger code when forwarding has just been chosen, not when "send" is hit (Application_ItemSend); maybe something like Application_ItemForward (another made up word). I'm just stressing, I'm not trying to create a forwarding as myItem.Forward might do; I'm trying to figure out how to react when the forwarding has already been initiated such as by alt-W.


(FYI my intent is to automatically and always prepend
myAttachment.DisplayName & "(size:" & Format(myAttachment.Size, "0,0") & ")"
to the mailItem's .Body when alt-W is hit (i.e., when forwarding is chosen), from
For Each myAttachment In Inspector.CurrentItem.Attachments
or such.)
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Outlook version
Outlook 2007
Email Account
Exchange Server
Thank you. Sorry for delay in responding, while grateful for your fast response.

I put all three routines (with End Subs) in ThisOutlookSession, added Dims provisionally to satisfy Option Explicit, added the Word reference, and ran, but none of them fired upon reply or reply all or forward. It looks good but I put Stop in each routine and none of them are executing when I go alt-R, alt-L, alt-W.

FYI I already had
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
and that does capture when Send occurs, just to establish that I'm not so completely fouled up that I am using ThisOutlookSessionMisspelled or such.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
it works here in outlook 2007 - but i did notice that it doesn't work with some messages. I used the macros at http://www.slipstick.com/developer/code-samples/insert-attachment-names-replying/
and copied one, renamed it
Private Sub oItem_Forward(ByVal Response As Object, Cancel As Boolean)
- changed the string to
strAtt = strAtt & "<<" & oAtt.FileName & " " & oAtt.Size / 1024 & "KB >> "

The attachment names and sizes are added to the messages when I reply, forward or reply all.
<<image001.png 7.2568359375KB >> <<May 2014 Alternative.pdf 4447.828125KB >>

Oh, if you use my code, it only gets attachments over 5KB - you will need to reduce the size if the attachments are shown as 5 KB or less in the attachment line.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
oh, and during testing, you need to select a different message - it won't work to keep testing on one message as it uses on selection change.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
once I remembered the need to select a different message when testing, I finally got the file size to round. :)

strAtt = strAtt & "<<" & oAtt.FileName & " " & Round(oAtt.Size / 1024, 2) & "KB >> "
 
Outlook version
Outlook 2007
Email Account
Exchange Server
Thank you, but every message I've tried in 2007 does not hit the code. It does hit
Private Sub Application_ItemSend
when I went alt-S on a reply, but none of the routines you mentioned fired off (I put a breakpoint or Stop statement in each).

Both changing the code sub name from Reply to Forward, and from Reply All to Forward, neither hit. :( :( :(

In case it's helpful, my references are

Visual Basic for Applications
Microsoft Outlook 12.0 Object Library
OLE Automation
Microsoft Office 12.0 Object Library
Microsoft Word 12.0 Object Library

I do use Option Explicit, and compile is okay.
 
Outlook version
Outlook 2007
Email Account
Exchange Server
It's strange, 2 times out of 15, the code fired off. It worked swell when it did, but !!

The selection change is a little awkward to do so it would be great if that wasn't required. Worse than that, though, IT is not firing most of the time either though :(
 
Outlook version
Outlook 2007
Email Account
Exchange Server
From the few times I've got it to work, I've observed that if someone has an image as their "signature" then that is counted in the attachments collection. That is, an "inline image" is counted as an attachment (if I'm wording this correctly). Example, <<image001.png 8KB >>

Also, restarting Outlook (2007 anyway) can make it start catching the code after it "stops doing so." At some point it stops capturing the reply or forward (and for that matter, selection change from arrowing through the message list), and the only remedy seems to be to restart OL.

Suggestion for code:
strAtt = strAtt & "<<" & oAtt.FileName & " " & Format(oAtt.Size / 1024, "0") & " KB >> "
where Format command in this case produces
7 KB
rather than something like
6.715543 KB

FWIW I also preceded that with these 3 lines and a Dim for i
If Len(strAtt) < 1 Then strAtt = "Prior message attachments over 5K: "
i = Len("Prior message attachments over 5K: ")
If Len(strAtt) > i Then strAtt = strAtt & " ; "
strAtt = strAtt & "<<" & oAtt.FileName & " " & Format(oAtt.Size / 1024, "0") & " KB >> "
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Correct on the signature images - that is why i had the original code set to skip images smaller than 5200 bytes - images in many signatures are smaller. But my test message had a 5 KB pdf and I thought it wasn't working. :)

One thing you could do is check file names from the right and skip jpg, png, or gif if under 5200 (or higher if those aren't files you are looking for).
 
Top