New Message vs Replies

Roderick_E

Well-known Member
Joined
Oct 13, 2007
Messages
2,051
I want to use the user's Outlook "New Message" default email signature but my code is using the replies/forwards email address. How do I distinguish since the user can name it anything? Thanks

Code:
Call SendMessage(ToRecipients, CCRecipients, BCCRecipients, stSubject, vaMsg, imAttachment, senderstr)

calls function...

Code:
Sub SendMessage(myRecipient As String, mycc As String, mybcc As String, mySubject As String, Optional myBody As String, Optional myFileName As String, Optional mySender As String)
On Error Resume Next
Dim myObject As Object
Dim myItem As Object
Dim strarray As String
Dim strunbound() As String
Dim Z As Long
Dim sSignat As Variant
Dim sPath As String


Set myObject = CreateObject("Outlook.Application")
Set myItem = myObject.CreateItem(0)


With myItem
.display
.Subject = mySubject
.To = myRecipient
.cc = mycc
.bcc = mybcc
If Trim(mySender) <> "" Then
.SentOnBehalfOfName = mySender
End If
If Trim(myBody) <> "" Then
'.Body = myBody


sPath = Dir(Environ("appdata") & "\Microsoft\Signatures\*.htm", vbNormal)
        sPath = Environ("appdata") & "\Microsoft\Signatures\" & sPath
        sSignat = GetSignature(sPath)
        'MsgBox sSignat
      '.HTMLBody = myBody & String(4, vbCrLf) & sSignat


'.HTMLBody = myBody & "<br>" & .HTMLBody
.HTMLBody = myBody & sSignat '& "<br>" & .HTMLBody
End If


'attach one file
If Trim(myFileName) <> "" Then
If InStr(myFileName, ",") = 0 Then
If Dir(myFileName) <> "" Then
.Attachments.Add (myFileName)
End If
Else 'multiple files
strarray = myFileName
 strunbound = Split(myFileName, ",")
 For Z = LBound(strunbound) To UBound(strunbound)
 .Attachments.Add (strunbound(Z))
Next Z
End If
End If
.Send
End With


Set myItem = Nothing
Set myObject = Nothing
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
This here will insert the default HTML signature. So .Display first to generate the default mail, then replace it with which ever string you create & the .Displayed one.

Code:
.HTMLBody = myBody & sSignat '& "" & .HTMLBody
 
Upvote 0
Hmm it is using the first email signature in an alphabetical list.
test with:
Code:
Sub test()
sPath = Dir(Environ("appdata") & "\Microsoft\Signatures\*.htm", vbNormal)
MsgBox sPath
End Sub

Somewhere, Outlook has to be storing the "New Message" signature to use. I need to find that if anyone can help. Thanks
 
Upvote 0
You can set the default in File >> Options >> Mail >> Signatures (or new message >> Message >> Signature >> Signatures)

Could it be true that your end users all have a signature called something like aaa and this is default for both new messages and forward/replies?

Incidentally I tested creating several signatures including one named zzz, set this as my default and ran a test VBA create mail. Worked a treat...
 
Upvote 0
You can set the default in File >> Options >> Mail >> Signatures (or new message >> Message >> Signature >> Signatures)

Could it be true that your end users all have a signature called something like aaa and this is default for both new messages and forward/replies?

Incidentally I tested creating several signatures including one named zzz, set this as my default and ran a test VBA create mail. Worked a treat...

Hmm... our tests showed my test code in reply #3 would always return the signature in alphabetical order. I'm trying to "programically" figure out the users "New Message" signature. I know how they are setting it with File/Options...blah blah blah but how do I find it via VBA? :) I wish Oultlook's vba editor had record macro, then I would easily figure it out. Thanks for helping me on this btw.
 
Upvote 0
I might be missing the point, is the ultimate goal to ALWAYS use whichever signature is the default as set by the user? Should that be the case don't go hunting down an alternative... See below will always set the user defined default (I've set references btw)

Code:
Sub RoderickE()
Dim OA As Outlook.Application
Dim OM As Outlook.MailItem


Set OA = New Outlook.Application
Set OM = OA.CreateItem(olMailItem)


With OM
    .Display
    .HTMLBody = "SomeText" & .HTMLBody
End With
End Sub
 
Upvote 0
I might be missing the point, is the ultimate goal to ALWAYS use whichever signature is the default as set by the user? Should that be the case don't go hunting down an alternative... See below will always set the user defined default (I've set references btw)

Code:
Sub RoderickE()
Dim OA As Outlook.Application
Dim OM As Outlook.MailItem


Set OA = New Outlook.Application
Set OM = OA.CreateItem(olMailItem)


With OM
    .Display
    .HTMLBody = "SomeText" & .HTMLBody
End With
End Sub

Ok let me test some more because, yes that is the goal. Thanks
 
Upvote 0
I might be missing the point, is the ultimate goal to ALWAYS use whichever signature is the default as set by the user? Should that be the case don't go hunting down an alternative... See below will always set the user defined default (I've set references btw)

Code:
Sub RoderickE()
Dim OA As Outlook.Application
Dim OM As Outlook.MailItem


Set OA = New Outlook.Application
Set OM = OA.CreateItem(olMailItem)


With OM
    .Display
    .HTMLBody = "SomeText" & .HTMLBody
End With
End Sub

Dim OA As Outlook.Application returns popup error User-defined type not defined
 
Upvote 0
Yeah, sorry I wasn't clear on my explanation of " (I've set references btw)"

You need to include the Outlook Library in VBA, Tools>>References>> Microsoft Outlook xx.0 Object Library switch xx for your version of Office

The generic code without the library is:

Code:
Sub RoderickE()
Dim OA As Object
Dim OM As Object


Set OA = CreateObject("Outlook.Application")
Set OM = OA.CreateItem(0)


With OM
    .Display
    .HTMLBody = "SomeText" & .HTMLBody
End With
End Sub
 
Last edited:
Upvote 0
Yeah, sorry I wasn't clear on my explanation of " (I've set references btw)"

You need to include the Outlook Library in VBA, Tools>>References>> Microsoft Outlook xx.0 Object Library switch xx for your version of Office

The generic code without the library is:

Code:
Sub RoderickE()
Dim OA As Object
Dim OM As Object


Set OA = CreateObject("Outlook.Application")
Set OM = OA.CreateItem(0)


With OM
    .Display
    .HTMLBody = "SomeText" & .HTMLBody
End With
End Sub

No worries, I was just being dense and didn't follow. I'm sure you figured I should have known as much :)
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,922
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top