Randy Schmidt
New Member
- Outlook version
- Outlook 2016 64 bit
- Email Account
- Office 365 Exchange
I am new to Outlook VBA and cannot figure out how to forward a message with added text, keeping the original message intact. Here is the code I'm trying (and I really don't understand a lot of it):
Sub Forward_Invoice_To_Joseph()
Dim objMail As Outlook.MailItem
Dim strHTML As String
Dim Msg As Object
Set Msg = HTMLBody
strHTML = "Hi Joseph,<p><p>Please advise if this invoice meets your approval<p><p>Thanks,<br>Randy"
Set objItem = GetCurrentItem()
Set objMail = objItem.Forward
Set objApp = CreateObject("Outlook.Application")
Set objSelection = objApp.ActiveExplorer.Selection
objMail.To = "xxx@xxx.edu"
objMail.CC = "xxx@xxx.edu"
With objMail
.BodyFormat = olFormatHTML
.HTMLBody = strHTML & Msg.HTMLBody
End With
objMail.Display
Set objItem = Nothing
Set objMail = Nothing
End Sub
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
Case Else
End Select
End Function
I copied and pasted parts of this code from the resources I found (like this website). I am simply trying to preface a forwarded message with what's in strHTML. It took me a long time to figure this part out but it does work. However, the original message is gone when I execute the macro. Please help me understand what I'm doing wrong. Once I do, I have many very similar repetitive messages and forwards that I would replicate using this type of code.
Thank You,
RS
Sub Forward_Invoice_To_Joseph()
Dim objMail As Outlook.MailItem
Dim strHTML As String
Dim Msg As Object
Set Msg = HTMLBody
strHTML = "Hi Joseph,<p><p>Please advise if this invoice meets your approval<p><p>Thanks,<br>Randy"
Set objItem = GetCurrentItem()
Set objMail = objItem.Forward
Set objApp = CreateObject("Outlook.Application")
Set objSelection = objApp.ActiveExplorer.Selection
objMail.To = "xxx@xxx.edu"
objMail.CC = "xxx@xxx.edu"
With objMail
.BodyFormat = olFormatHTML
.HTMLBody = strHTML & Msg.HTMLBody
End With
objMail.Display
Set objItem = Nothing
Set objMail = Nothing
End Sub
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
Case Else
End Select
End Function
I copied and pasted parts of this code from the resources I found (like this website). I am simply trying to preface a forwarded message with what's in strHTML. It took me a long time to figure this part out but it does work. However, the original message is gone when I execute the macro. Please help me understand what I'm doing wrong. Once I do, I have many very similar repetitive messages and forwards that I would replicate using this type of code.
Thank You,
RS