The below code copies a few cells from a spreadhsheet and responds to the sender of the selected email and puts "Trades complete." in the body and displays the sender's original email with the correct formatting, similar as if you click the Reply button.
I have it attached to a hotkey, Ctrl + Shift + R.
Works fine if I go into the Code and click the arrow to run it, and it adds the text "Trades complete." as it should.
However, if I run it by triggering it through the HotKey, Ctrl + Shift + R, it generates the reply email but doesn't add the "Trades Complete" text.
Anything I can do to fix this.
Thx.
Sub TradesCompleteEmail()
'Shortcut Key = Shift + Ctrl + R
Dim OutlookApp As Object
Dim OutlookNamespace As Object
Dim CurrentExplorer As Object
Dim SelectedEmail As Object
Dim ReplyEmail As Object
' Create Outlook application object
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set CurrentExplorer = OutlookApp.ActiveExplorer
' Check if there is an active email selected
If CurrentExplorer.Selection.Count > 0 Then
Set SelectedEmail = CurrentExplorer.Selection.Item(1)
senderEmail = SelectedEmail.SenderEmailAddress
Set CurrentCell = ActiveCell
' Reply to the selected email
Set ReplyEmail = SelectedEmail.Reply
With ReplyEmail
.HTMLBody = "Trades Complete." & ReplyEmail.HTMLBody
.Display
End With
Else
MsgBox "No email selected.", vbExclamation
End If
' Clean up
Set ReplyEmail = Nothing
Set SelectedEmail = Nothing
Set CurrentExplorer = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing
End Sub
I have it attached to a hotkey, Ctrl + Shift + R.
Works fine if I go into the Code and click the arrow to run it, and it adds the text "Trades complete." as it should.
However, if I run it by triggering it through the HotKey, Ctrl + Shift + R, it generates the reply email but doesn't add the "Trades Complete" text.
Anything I can do to fix this.
Thx.
Sub TradesCompleteEmail()
'Shortcut Key = Shift + Ctrl + R
Dim OutlookApp As Object
Dim OutlookNamespace As Object
Dim CurrentExplorer As Object
Dim SelectedEmail As Object
Dim ReplyEmail As Object
' Create Outlook application object
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set CurrentExplorer = OutlookApp.ActiveExplorer
' Check if there is an active email selected
If CurrentExplorer.Selection.Count > 0 Then
Set SelectedEmail = CurrentExplorer.Selection.Item(1)
senderEmail = SelectedEmail.SenderEmailAddress
Set CurrentCell = ActiveCell
' Reply to the selected email
Set ReplyEmail = SelectedEmail.Reply
With ReplyEmail
.HTMLBody = "Trades Complete." & ReplyEmail.HTMLBody
.Display
End With
Else
MsgBox "No email selected.", vbExclamation
End If
' Clean up
Set ReplyEmail = Nothing
Set SelectedEmail = Nothing
Set CurrentExplorer = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing
End Sub