Paste the following in a regular module :
VBA Code:
Option Explicit
Sub SimpleOutlookEmailDisplayRunFromExcelOrOutlookWithTextSignature()
'This assumes that Outlook is already open to simplify the code
Dim OutApp As Object
Dim OutMail As Object
Dim sEmailBody As String
Dim sSignature As String
'Attempt to create an Outlook object
On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
Err.Clear
MsgBox "NOTHING DONE. The Outlook Object could not be created from Excel." & vbCrLf & _
"Try again when Outlook is open."
Exit Sub
End If
On Error GoTo 0
'Create the Email Body
sEmailBody = _
"This is line one of the email body." & vbCrLf & _
"This is line two. " & _
"This is a continuation of line two."
'Create the Outlook Mail Object
Set OutMail = OutApp.CreateItem(0)
'Grab the Signature
OutMail.display
sSignature = OutMail.body
'Determine the values to be sent
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Info Request"
.body = sEmailBody & vbCrLf & sSignature
.display
'.Send - comment out the 'Display line' if you want to send
End With
'Clear the Object Pointers
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Function GetTextSignatureAsFirstNameForOutlook(OutApp As Object) As String
Dim myNamespace As Object
Dim iPos As Long
Dim sUserName As String
Set myNamespace = OutApp.Application.GetNamespace("MAPI")
'Get the 'User Name'
'Parse at the 'First Space'
sUserName = Trim(myNamespace.CurrentUser)
iPos = InStr(sUserName, " ")
If iPos > 0 Then
sUserName = Left(sUserName, iPos - 1)
End If
'Set the Return Value
GetTextSignatureAsFirstNameForOutlook = sUserName
End Function
Instructions from Outlook 'How to include a signature with image'
Include or change a signature in outgoing messages
Add a signature to messages
You can set a default signature to be added to all your outgoing messages, or you can insert a signature manually into outgoing messages on an individual basis. Do one of the following:
Insert a signature automatically
- In a new message, on the Message tab, in the Include group, click Signature, and then click Signatures.
Note You can also access the signature options that are available on the Message tab after you click Reply, Reply to All, or Forward in an open message.
- On the E-mail Signature tab, in the Select signature to edit list, select the signature that you want.
- Under Choose default signature, in the New messages list, select the signature that you want.
- If you want to include a signature in message replies and in forwarded messages, in the Replies/forwards list, select the signature. If not, select none.
- Click OK.
- To add the default signature to a currently open message, on the Message tab, in the Include group, click Signatures, and then select the signature.
Insert a signature manually
- In a new message, on the Message tab, in the Include group, click Signature, and then select the signature that you want.
Note You can also access the signature options that are available on the Message tab after you click Reply, Reply to All, or Forward in an open message.