Discussion:
Macro & buttons to reply Dear ..., Regards ...
(too old to reply)
Mark
2010-07-30 01:25:23 UTC
Permalink
Thanks to members of these board for help in creating this

For the sake of anyone else who wants to play with it, the following is what
I came up with and it works for me, but no guarantees for anybody else.

I have put buttons on my task bar. Actually I have a few: Dear, Reply_all,
Hi, Hello, Many thanks. All have differing salutations etc. I've also added
shortcut keys to the most used.

Cheers
Mark

(BTW Dear_reply_all uses Set NewMsg = myItem.ReplyAll)


-----------------------

Sub Dear_Name_if()
Dim myItem As Outlook.MailItem
Dim NewMsg As Outlook.MailItem

' get valid ref to current item
On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set myItem = ActiveExplorer.Selection.Item(1)
myItem.Display
Case "Inspector"
Set myItem = ActiveInspector.CurrentItem
Case Else
End Select
On Error GoTo 0

If myItem Is Nothing Then
MsgBox "Could not use current item. Please select or open a single
email.", _
vbInformation
GoTo ExitProc

End If

Set NewMsg = myItem.Reply

With NewMsg

NewMsg.BodyFormat = olFormatHTML


.HTMLBody = "<span style=""font-size:11.0pt;font-family:
Arial;color:#1F497D""><p>Regards, Mark" & vbCr & vbCr & vbCr & vbCr & "</p>"
& .HTMLBody

.HTMLBody = "<span style=""font-size:11.0pt;font-family:
Arial;color:#1F497D""><p> " & "</p><br />" & .HTMLBody


If myItem.SenderName, " " Then

.HTMLBody = "<span style=""font-family : Arial;font-size :
11pt;color:#1F497D""><p>Dear " & Left$(myItem.SenderName, InStr(1,
myItem.SenderName, " ") - 1) & ",</p></span>" & .HTMLBody

Else
.HTMLBody = "<span style=""font-family : Arial;font-size :
11pt;color:#1F497D""><p>Dear " & Left$(myItem.SenderName, InStr(1,
myItem.SenderName, "@") - 1) & ",</p></span>" & .HTMLBody

End If


End With

myItem.Close olDiscard

NewMsg.Display


ExitProc:
Set myItem = Nothing
Set NewMsg = Nothing

End Sub
Mark
2010-07-30 03:28:39 UTC
Permalink
Sorry all, there is a bug. I didn't test it on enough of my email before
getting over enthusiastic. The following line of code does not work, so it
is useless at this point.

If myItem.SenderName, " " Then

Obviously I am just a beginner.

Somehow I need to have it check if it contains " ". Or alternately if it
does not contain " ".

I've run out of time for now.

Sorry

Mark
Ken Slovak
2010-07-30 14:07:33 UTC
Permalink
Look at the Instr() function. You pass the start index to search from,
string to search in, string to search for and you get back a value. If
greater than 0 the index is where the search string is located.

To just remove a space use Replace(), where you provide the string to
search, what to search for and what to replace it with if found.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by Mark
Sorry all, there is a bug. I didn't test it on enough of my email before
getting over enthusiastic. The following line of code does not work, so it
is useless at this point.
If myItem.SenderName, " " Then
Obviously I am just a beginner.
Somehow I need to have it check if it contains " ". Or alternately if it
does not contain " ".
I've run out of time for now.
Sorry
Mark
Mark
2010-08-02 03:56:00 UTC
Permalink
Thanks Ken

Thanks for your help. I can now see what the code is doing much better.

What I'm trying to do is search to see if a space exists or not.

Cheers
Mark
Post by Ken Slovak
Look at the Instr() function. You pass the start index to search from,
string to search in, string to search for and you get back a value. If
greater than 0 the index is where the search string is located.
To just remove a space use Replace(), where you provide the string to
search, what to search for and what to replace it with if found.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by Mark
Sorry all, there is a bug. I didn't test it on enough of my email before
getting over enthusiastic. The following line of code does not work, so
it is useless at this point.
If myItem.SenderName, " " Then
Obviously I am just a beginner.
Somehow I need to have it check if it contains " ". Or alternately if it
does not contain " ".
I've run out of time for now.
Sorry
Mark
Ken Slovak
2010-08-02 13:57:16 UTC
Permalink
For that I'd use Instr() with a search for a space. Any return value greater
than 0 indicates a space was found and where. There may be more than one
space, but the first one will be returned.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by Mark
Thanks Ken
Thanks for your help. I can now see what the code is doing much better.
What I'm trying to do is search to see if a space exists or not.
Cheers
Mark
Post by Ken Slovak
Look at the Instr() function. You pass the start index to search from,
string to search in, string to search for and you get back a value. If
greater than 0 the index is where the search string is located.
To just remove a space use Replace(), where you provide the string to
search, what to search for and what to replace it with if found.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by Mark
Sorry all, there is a bug. I didn't test it on enough of my email before
getting over enthusiastic. The following line of code does not work, so
it is useless at this point.
If myItem.SenderName, " " Then
Obviously I am just a beginner.
Somehow I need to have it check if it contains " ". Or alternately if it
does not contain " ".
I've run out of time for now.
Sorry
Mark
Loading...