Hi all,
The code below adds "Hello FirstName," to the email body when replying to an email. Nice.
The issue however is, that it opens two reply windows. The code does its work twice.
What has to be changed to the code so it only happens once?
Thanks
The code below adds "Hello FirstName," to the email body when replying to an email. Nice.
The issue however is, that it opens two reply windows. The code does its work twice.
What has to be changed to the code so it only happens once?
Thanks
Public WithEvents GExplorer As Outlook.Explorer
Public WithEvents GMailItem As Outlook.MailItem
Private Sub Application_Startup()
Set GExplorer = Outlook.Application.ActiveExplorer
End Sub
Private Sub GExplorer_SelectionChange()
Dim xItem As Object
On Error Resume Next
Set xItem = GExplorer.Selection.Item(1)
If xItem.Class <> olMail Then Exit Sub
Set GMailItem = xItem
End Sub
Private Sub GMailItem_Reply(ByVal Response As Object, Cancel As Boolean)
AutoAddGreetingtoReply Response
End Sub
Private Sub GMailItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
AutoAddGreetingtoReply Response
End Sub
Sub AutoAddGreetingtoReply(Item As Object)
Dim oMail As MailItem
Dim oReply As MailItem
Dim GreetTime As String
Dim olInsp As Inspector
Dim wdDoc As Object
Dim oRng As Object
Select Case Application.ActiveWindow.Class
Case olExplorer
Set oMail = ActiveExplorer.Selection.Item(1)
End Select
Set oReply = oMail.ReplyAll
With oReply
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
Set oRng = wdDoc.Range
.Display
With oRng
.collapse 1
.Text = "Hello " & Split(oMail.SenderName)(0) & "," & vbCr & vbCr
.collapse 0
.Select
End With
End With
lbl_Exit:
Set oMail = Nothing
Set oReply = Nothing
Set olInsp = Nothing
Set wdDoc = Nothing
Set oRng = Nothing
Exit Sub
End Sub