|
|
|
date: Tue, 22 Jul 2008 21:28:07 +1000,
group: microsoft.public.office.developer.outlook.vba
back
Re: Macro get name from TO and put in Dear ...
Here's one way. This is air code so please test it first. It takes a
received email and crafts a reply with the "To" name in the message
body.
Sub DearJohn()
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
NewMsg.Body = "Dear " & Left$(myItem.SenderName, _
InStr(1, myItem.SenderName, " ") - 1) & ","
myItem.Close olDiscard
NewMsg.Display
ExitProc:
Set myItem = Nothing
Set NewMsg = Nothing
End Sub
HTH,
JP
On Jul 22, 7:28 am, "Mark" wrote:
> Hi
>
> Newbie playing with Outlook VBA.
>
> I'd like to get the name from TO and copy it to the text to end up with Dear
> .... when I hit a keyboard shortcut
>
> For example, say To is John Brown. I'd like to end up with Dear John when I
> hit a keyboard shortcut
>
> Thanks Mark
date: Tue, 22 Jul 2008 05:32:13 -0700 (PDT)
author: JP
Re: Macro get name from TO and put in Dear ...
Many thanks, will give it a try.
Cheers, Mark
"JP" wrote in message
news:71658b52-6691-428c-901b-99c698ddf311@x41g2000hsb.googlegroups.com...
Here's one way. This is air code so please test it first. It takes a
received email and crafts a reply with the "To" name in the message
body.
Sub DearJohn()
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
NewMsg.Body = "Dear " & Left$(myItem.SenderName, _
InStr(1, myItem.SenderName, " ") - 1) & ","
myItem.Close olDiscard
NewMsg.Display
ExitProc:
Set myItem = Nothing
Set NewMsg = Nothing
End Sub
HTH,
JP
On Jul 22, 7:28 am, "Mark" wrote:
> Hi
>
> Newbie playing with Outlook VBA.
>
> I'd like to get the name from TO and copy it to the text to end up with
> Dear
> .... when I hit a keyboard shortcut
>
> For example, say To is John Brown. I'd like to end up with Dear John when
> I
> hit a keyboard shortcut
>
> Thanks Mark
date: Wed, 23 Jul 2008 08:07:50 +1000
author: Mark
Re: Macro get name from TO and put in Dear ...
Thanks JP
Yes works really well, exactly what I want.
One thing for my particular use. At present it removes the original message.
How do I get it to leave the original message in the email?
Many thanks for your help
Much appreciated
Mark
"JP" wrote in message
news:71658b52-6691-428c-901b-99c698ddf311@x41g2000hsb.googlegroups.com...
Here's one way. This is air code so please test it first. It takes a
received email and crafts a reply with the "To" name in the message
body.
Sub DearJohn()
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
NewMsg.Body = "Dear " & Left$(myItem.SenderName, _
InStr(1, myItem.SenderName, " ") - 1) & ","
myItem.Close olDiscard
NewMsg.Display
ExitProc:
Set myItem = Nothing
Set NewMsg = Nothing
End Sub
HTH,
JP
On Jul 22, 7:28 am, "Mark" wrote:
> Hi
>
> Newbie playing with Outlook VBA.
>
> I'd like to get the name from TO and copy it to the text to end up with
> Dear
> .... when I hit a keyboard shortcut
>
> For example, say To is John Brown. I'd like to end up with Dear John when
> I
> hit a keyboard shortcut
>
> Thanks Mark
date: Wed, 23 Jul 2008 09:10:39 +1000
author: Mark
Re: Macro get name from TO and put in Dear ...
Change this line:
NewMsg.Body = "Dear " & Left$(myItem.SenderName, _
InStr(1, myItem.SenderName, " ") - 1) & ","
to this:
NewMsg.Body = "Dear " & Left$(myItem.SenderName, _
InStr(1, myItem.SenderName, " ") - 1) & "," & vbCr & myItem.Body
Let me know if it works.
Thx,
JP
On Jul 22, 7:10 pm, "Mark" wrote:
> Thanks JP
>
> Yes works really well, exactly what I want.
>
> One thing for my particular use. At present it removes the original message.
> How do I get it to leave the original message in the email?
>
> Many thanks for your help
>
> Much appreciated
> Mark
>
date: Wed, 23 Jul 2008 07:09:45 -0700 (PDT)
author: JP
Re: Macro get name from TO and put in Dear ...
Many thanks JP
Will give it a go and let you know.
I have out the previous version as a button on the menu. It works relly
well.
Cheers
Mark
"JP" wrote in message
news:82ceaf16-d4ee-41ad-b2a4-beec4ddca806@25g2000hsx.googlegroups.com...
Change this line:
NewMsg.Body = "Dear " & Left$(myItem.SenderName, _
InStr(1, myItem.SenderName, " ") - 1) & ","
to this:
NewMsg.Body = "Dear " & Left$(myItem.SenderName, _
InStr(1, myItem.SenderName, " ") - 1) & "," & vbCr & myItem.Body
Let me know if it works.
Thx,
JP
On Jul 22, 7:10 pm, "Mark" wrote:
> Thanks JP
>
> Yes works really well, exactly what I want.
>
> One thing for my particular use. At present it removes the original
> message.
> How do I get it to leave the original message in the email?
>
> Many thanks for your help
>
> Much appreciated
> Mark
>
date: Thu, 24 Jul 2008 14:26:35 +1000
author: Mark
Re: Macro get name from TO and put in Dear ...
BTW
I have been playing with this concept and learning a bit of VBA in the
process. I decided to try and include fields to look like a reply email from
Outlook (see code below). All works ok for me, though it is a bit slow
somtimes.
If anybody has any suggestions on how to improve this I'd like to hear from
you.
Mark
Sub Dear()
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
'Use this if original message is to be deleted
'NewMsg.Body = "Dear " & Left$(myItem.SenderName, _
' InStr(1, myItem.SenderName, " ") - 1) & ","
'
'Use this if original message is to be retained
NewMsg.Body = "Dear " & Left$(myItem.SenderName, InStr(1, myItem.SenderName,
" ") - 1) _
& "," & vbCr & vbCr & "Regards, Martin" & vbCr &
"_____________________________________________" _
& vbCr & "From: " & (myItem.SenderName) & vbCr & "Sent: " & (myItem.SentOn)
& vbCr & "To: " & (myItem.To) & vbCr & "Subject: " & (myItem.Subject) & vbCr
& vbCr & myItem.Body
myItem.Close olDiscard
NewMsg.Display
ExitProc:
Set myItem = Nothing
Set NewMsg = Nothing
End Sub
"Mark" wrote in message
news:uPN65VU7IHA.3260@TK2MSFTNGP03.phx.gbl...
> Many thanks JP
>
> Will give it a go and let you know.
>
> I have out the previous version as a button on the menu. It works relly
> well.
>
> Cheers
> Mark
>
> "JP" wrote in message
> news:82ceaf16-d4ee-41ad-b2a4-beec4ddca806@25g2000hsx.googlegroups.com...
> Change this line:
>
> NewMsg.Body = "Dear " & Left$(myItem.SenderName, _
> InStr(1, myItem.SenderName, " ") - 1) & ","
>
> to this:
>
> NewMsg.Body = "Dear " & Left$(myItem.SenderName, _
> InStr(1, myItem.SenderName, " ") - 1) & "," & vbCr & myItem.Body
>
>
> Let me know if it works.
>
> Thx,
> JP
>
>
> On Jul 22, 7:10 pm, "Mark" wrote:
>> Thanks JP
>>
>> Yes works really well, exactly what I want.
>>
>> One thing for my particular use. At present it removes the original
>> message.
>> How do I get it to leave the original message in the email?
>>
>> Many thanks for your help
>>
>> Much appreciated
>> Mark
>>
>
>
date: Tue, 2 Sep 2008 11:02:26 +1000
author: Mark
|
|