This code dosn't work in Outlook 2010
I get the error in
strGreetName = Left$(Msg.SenderName, InStr(1, Msg.SenderName, " ") - 1)
Printable View
This code dosn't work in Outlook 2010
I get the error in
strGreetName = Left$(Msg.SenderName, InStr(1, Msg.SenderName, " ") - 1)
Can you paste your code directly into the post editor (and wrap it in code tags)? I can barely read it and anyway I can't cut and paste it to test it.
code located on page
vbaexpress.com/kb/getarticle.php?kb_id=1046
Knew it looked familiar. What error do you get? Did you try stepping through the code?
step1
step 2
debug - step 3 - look first post ...
and try 2
Are you selecting an email (not a meeting request, post, etc) before running the code?
So I understand you correctly, when you run it again you don't get an error in the same place, you're getting an error in a later line of code? What is the error message?
Hi,
I'm reviving an old thread since I am struggling with a derivative of this macro
When I try to run this macro when I am in reply mode, I get the debug error in the following line:Code:Sub InsertNameInReply()
Dim Msg As Outlook.MailItem
Dim MsgReply As Outlook.MailItem
Dim strGreetName As String
Dim lGreetType As Long
' set reference to open/selected mail item
On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set Msg = ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set Msg = ActiveInspector.CurrentItem
Case Else
End Select
On Error GoTo 0
If Msg Is Nothing Then GoTo ExitProc
strGreetName = Mid$(Msg.SenderName, 2 + InStr(1, Msg.SenderName, ", ", Len(Msg.SenderName)) - 1)
Set MsgReply = Msg.Reply
With MsgReply
.subject = "RE:" & Msg.subject
.HTMLBody = "<span style=""font-family : verdana;font-size : 10pt""><p>Hello " & strGreetName & ",</p></span>" & .HTMLBody
.Display
End With
ExitProc:
Set Msg = Nothing
Set MsgReply = Nothing
End Sub
Can anyone help me with this code such that it works on an open email as well?Code:Set MsgReply = Msg.Reply
Thanks.
first remove on error resume next, so if any error occurs earlier in the code it will not be hidden
I commented out the following:Code:Sub InsertNameInReply()
Dim Msg As Outlook.MailItem
Dim MsgReply As Outlook.MailItem
Dim strGreetName As String
Dim lGreetType As Long
' set reference to open/selected mail item
'On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set Msg = ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set Msg = ActiveInspector.CurrentItem
Case Else
End Select
On Error GoTo 0
If Msg Is Nothing Then GoTo ExitProc
strGreetName = Mid$(Msg.SenderName, 2 + InStr(1, Msg.SenderName, ", ", Len(Msg.SenderName)) - 1)
Set MsgReply = Msg.Reply
With MsgReply
.subject = "RE:" & Msg.subject
.HTMLBody = "<span style=""font-family : verdana;font-size : 10pt""><p>Hello " & strGreetName & ",</p></span>" & .HTMLBody
.Display
End With
ExitProc:
Set Msg = Nothing
Set MsgReply = Nothing
End Sub
yet the macro failed onCode:On Error Resume Next
Please advise what else could I do?Code:Set MsgReply = Msg.Reply
Thanks a lot for pitching in to help.
what error are you getting, it certainly looks correct and testing similar gives no error
try
of course on its own that will still cause an error on the next line, but at least you can then fixCode:If msg.Class = olMail Then set msgreply = msg.reply
I am trying to run this macro when an email is in Reply mode. As far as I understand the vba code, it's trying to set the email in reply mode. I think this is causing the error.
Can you help me with this?
Thanks.
i guess that explains it, you can not reply to an email that is already a reply
you could try to reply after the mail is sent or explicitly saved
if an email is not received, there is no one to reply to
Umm... I am seeking help to use this code when I AM in a reply mode. Can you please guide me with the necessary changes to the code provided?
what is it you want to achieve?Quote:
Can you please guide me with the necessary changes to the code provided?
you are already in reply mode, so what else do you want to do?
please explain exactly what you want to achieve
Perhaps my original post was not clear enough.
I am trying to insert a greeting using the code mentioned in this thread. I am ALREADY in reply mode when I WANT to use this code.
When I try to run this macro when I am in reply mode, I get the debug error in the following line:
Code:Set MsgReply = Msg.Reply
i am still not clear on what you want to achieve,Quote:
Perhaps my original post was not clear enough.
try changing to
does this do what you want?Code:strGreetName = Mid$(Msg.SenderName, 2 + InStr(1, Msg.SenderName, ", ", Len(Msg.SenderName)) - 1)
'Set MsgReply = Msg.Reply
With Msg
' .subject = "RE:" & Msg.subject ' in reply mode,this should already be assigned
.HTMLBody = "<span style=""font-family : verdana;font-size : 10pt""><p>Hello " & strGreetName & ",</p></span>" & .HTMLBody
.Display
End With
SenderName is on the original message not the reply, so this returns nothing.
strGreetName = Mid$(Msg.SenderName, 2 + InStr(1, Msg.SenderName, ", ", Len(Msg.SenderName)) - 1)
Debug.Print " strGreetName: " & strGreetName