The following should do the trick subject to a couple of provisos.
- You will need to set a reference to the outlook object library in Tools > references
- You need to enter the name of signature you wish to use where indicated. It will not insert signature graphics, so if necessary create a signature for the job.
- Complete the e-mail address(es) , subject line and Body text content where indicated.
If you want greater control including the ability to use signatures with graphics then you need the longer code in the link I posted earlier. Both versions will work.
Option Explicit
Sub Send_As_Mail_Attachment()
' Set a reference to the Outlook object library
' Send the document as an attachment in an Outlook Email message
'Enter the name of the signature ( does not insert graphics in signatures)
Const sText As String =
"signaturename"
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
Dim SigString As String
Dim Signature As String
On Error Resume Next
'Prompt the user to save the document
ActiveDocument.Save
'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
'Outlook wasn't running, start it from code
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
SigString = "C:\Users" & Environ("username") & _
"\AppData\Roaming\Microsoft\Signatures" & sText & ".htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If
'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.to = "someoneATsomewhere.com"
'Set the recipient for a copy is required
.BCC = "someoneelseATsomewhere.com"
.Subject = "This is the subject"
'create the body with html tags
.HTMLBody = "<font face=""Calibri"" size=""4"" >Please complete the attached form
" & _
"and return to the sender. <br><br>" _
& Signature
'Add the document as an attachment
.Attachments.Add Source:=ActiveDocument.FullName, _
Type:=olByValue, DisplayName:="Document as attachment"
.Display
End With
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub
Function GetBoiler(ByVal sFile As String) As String
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.ReadAll
ts.Close
End Function