Outlook Signature

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
786
Office Version
  1. 365
i Have this code and not error message when executed but it doesn't get the signature in the email, please help.

here is the code:


' Create a PDF from the current sheet and email it as an attachment through Outlook


Dim EmailSubject As String, EmailSignature As String
Dim CurrentMonth As String, DestFolder As String, PDFFile As String
Dim Email_To As String, Email_CC As String, Email_BCC As String, Email_body As String
Dim OpenPDFAfterCreating As Boolean, AlwaysOverwritePDF As Boolean, DisplayEmail As Boolean
Dim OverwritePDF As VbMsgBoxResult
Dim OutlookApp As Object, OutlookMail As Object
Dim Signature As String
CurrentMonth = ""


' *****************************************************
' ***** You Can Change These Variables *********


EmailSubject = "TNW a/c " & " " & ActiveSheet.Range("A1") & "," & " " & "Contra to offset A/R - A/P " & ActiveSheet.Range("c57") 'Change this to change the subject of the email. The current month is added to end of subj line
OpenPDFAfterCreating = False 'Change this if you want to open the PDF after creating it : TRUE or FALSE
AlwaysOverwritePDF = False 'Change this if you always want to overwrite a PDF that already exists :TRUE or FALSE
DisplayEmail = True 'Change this if you don't want to display the email before sending. Note, you must have a TO email address specified for this to work
Email_To = ActiveSheet.Range("C1") 'Change this if you want to specify To email e.g. ActiveSheet.Range("H1") to get email from cell H1
Email_CC = "accounts.receivable@navigata.ca"
Email_BCC = ""
Email_body = "Hi" & " " & ActiveSheet.Range("B1") & "," & vbCrLf & vbCrLf & ActiveSheet.Range("TORECONCILE") & vbCrLf & vbCrLf & ActiveSheet.Range("AGREETO") & "." & " " & ActiveSheet.Range("TOPAY") & vbCrLf & vbCrLf & "Please let me know if it's ok with you to proceed."
' ******************************************************
'Change only Mysig.htm to the name of your signature
SigString = Environ("appdata") & _
"\Microsoft\Signatures\JROSSI.htm"


If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If


On Error Resume Next

'Prompt for file destination
With Application.FileDialog(msoFileDialogFolderPicker)

If .Show = True Then

DestFolder = "C:\Documents and Settings\rossj1\Desktop\Excel Files\STATEMENT\EXCEL_PDF" '.SelectedItems(1)

Else

MsgBox "You must specify a folder to save the PDF into." & vbCrLf & vbCrLf & "Press OK to exit this macro.", vbCritical, "Must Specify Destination Folder"

Exit Sub

End If

End With


'Current month/year stored in H6 (this is a merged cell)
CurrentMonth = Mid(ActiveSheet.Range("H6").Value, InStr(1, ActiveSheet.Range("H6").Value, " ") + 1)

'Create new PDF file name including path and file extension
PDFFile = DestFolder & Application.PathSeparator & ActiveSheet.Range("FILENAMETO") _
& "_" & CurrentMonth & ".pdf"


'If the PDF already exists
If Len(Dir(PDFFile)) > 0 Then

If AlwaysOverwritePDF = False Then

OverwritePDF = MsgBox(PDFFile & " already exists." & vbCrLf & vbCrLf & "Do you want to overwriteit?", vbYesNo + vbQuestion, "File Exists")

On Error Resume Next
'If you want to overwrite the file then delete the current one
If OverwritePDF = vbYes Then

Kill PDFFile

Else

MsgBox "OK then, if you don't overwrite the existing PDF, I can't continue." _
& vbCrLf & vbCrLf & "Press OK to exit this macro.", vbCritical, "Exiting Macro"

Exit Sub

End If


Else

On Error Resume Next
Kill PDFFile

End If


If Err.Number <> 0 Then

MsgBox "Unable to delete existing file. Please make sure the file is not open or write protected." _
& vbCrLf & vbCrLf & "Press OK to exit this macro.", vbCritical, "Unable to Delete File"

Exit Sub

End If

End If



'Create the PDF
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=OpenPDFAfterCreating


'Create an Outlook object and new mail message
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)

'Display email and specify To, Subject, etc
With OutlookMail

.Display
.To = Email_To
.CC = Email_CC
.BCC = Email_BCC
.Subject = EmailSubject & CurrentMonth
.Body = Email_body
.Attachments.Add PDFFile

If DisplayEmail = False Then

.send

End If

End With
End Sub


Function GetBoiler(ByVal sFile As String) As String
'**** Kusleika
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[/CODE]

thank you,
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Please paste code between code tags. Click # icon on reply toolbar to insert the tags.
Code:
'.Body = Email_body
.htmlBody = Email_body & "<br>" & SigString

BR is inside the quotes to simulate vbCrLf in html syntax.
 
Last edited:
Upvote 0
i made the changes suggested but doesn't get the signature instead display the path this: C:\Documents and Settings\rossj1\Application Data\Microsoft\Signatures\JROSSI.htm

Code:
' Author - Philip Treacy  ::   http://www.linkedin.com/in/philiptreacy' http://www.MyOnlineTrainingHub.com/vba-to-create-pdf-from-excel-worksheet-then-email-it-with-outlook
' Date - 14 Oct 2013
' Create a PDF from the current sheet and email it as an attachment through Outlook


Dim EmailSubject As String, EmailSignature As String
Dim CurrentMonth As String, DestFolder As String, PDFFile As String
Dim Email_To As String, Email_CC As String, Email_BCC As String, Email_body As String
Dim OpenPDFAfterCreating As Boolean, AlwaysOverwritePDF As Boolean, DisplayEmail As Boolean
Dim OverwritePDF As VbMsgBoxResult
Dim OutlookApp As Object, OutlookMail As Object
Dim Signature As String
CurrentMonth = ""


' *****************************************************
' *****     You Can Change These Variables    *********


    EmailSubject = "TNW a/c " & " " & ActiveSheet.Range("A1") & "," & " " & "Contra to offset A/R - A/P " & ActiveSheet.Range("c57")  'Change this to change the subject of the email. The current month is added to end of subj line
    OpenPDFAfterCreating = False    'Change this if you want to open the PDF after creating it : TRUE or FALSE
    AlwaysOverwritePDF = False      'Change this if you always want to overwrite a PDF that already exists :TRUE or FALSE
    DisplayEmail = True 'Change this if you don't want to display the email before sending.  Note, you must have a TO email address specified for this to work
    Email_To = ActiveSheet.Range("C1")   'Change this if you want to specify To email e.g. ActiveSheet.Range("H1") to get email from cell H1
    Email_CC = "accounts.receivable@navigata.ca"
    Email_BCC = ""
    Email_body = "Hi" & " " & ActiveSheet.Range("B1") & "," & vbCrLf & vbCrLf & ActiveSheet.Range("TORECONCILE") & vbCrLf & vbCrLf & ActiveSheet.Range("AGREETO") & "." & " " & ActiveSheet.Range("TOPAY") & vbCrLf & vbCrLf & "Please let me know if it's ok with you to proceed."
' ******************************************************
 'Change only Mysig.htm to the name of your signature
    SigString = Environ("appdata") & _
                "C:\Documents and Settings\rossj1\Application Data\Microsoft\SignaturesJROSSI.htm"


                '"\Microsoft\Signatures\JROSSI.htm"


    If Dir(SigString) <> "" Then
        Signature = GetBoiler(SigString)
    Else
        Signature = ""
    End If


    On Error Resume Next
    
    'Prompt for file destination
    With Application.FileDialog(msoFileDialogFolderPicker)
        
        If .Show = True Then
        
            DestFolder = "C:\Documents and Settings\rossj1\Desktop\Excel Files\STATEMENT\EXCEL_PDF" '.SelectedItems(1)
            
        Else
        
            MsgBox "You must specify a folder to save the PDF into." & vbCrLf & vbCrLf & "Press OK to exit this macro.", vbCritical, "Must Specify  Destination Folder"
                
            Exit Sub
            
        End If
        
    End With


    'Current month/year stored in H6 (this is a merged cell)
    CurrentMonth = Mid(ActiveSheet.Range("H6").Value, InStr(1, ActiveSheet.Range("H6").Value, " ") + 1)
    
    'Create new PDF file name including path and file extension
    PDFFile = DestFolder & Application.PathSeparator & ActiveSheet.Range("FILENAMETO") _
               & "_" & CurrentMonth & ".pdf"


    'If the PDF already exists
    If Len(Dir(PDFFile)) > 0 Then
    
        If AlwaysOverwritePDF = False Then
        
            OverwritePDF = MsgBox(PDFFile & " already exists." & vbCrLf & vbCrLf & "Do you want to overwriteit?", vbYesNo + vbQuestion, "File Exists")
        
            On Error Resume Next
            'If you want to overwrite the file then delete the current one
            If OverwritePDF = vbYes Then
    
                Kill PDFFile
        
            Else
    
                MsgBox "OK then, if you don't overwrite the existing PDF, I can't continue." _
                    & vbCrLf & vbCrLf & "Press OK to exit this macro.", vbCritical, "Exiting Macro"
                
                Exit Sub
        
            End If


        Else
        
            On Error Resume Next
            Kill PDFFile
            
        End If


 If Err.Number <> 0 Then
        
            MsgBox "Unable to delete existing file.  Please make sure the file is not open or write protected." _
                    & vbCrLf & vbCrLf & "Press OK to exit this macro.", vbCritical, "Unable to Delete File"
                
            Exit Sub
        
        End If
            
    End If
   


    'Create the PDF
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=OpenPDFAfterCreating


    'Create an Outlook object and new mail message
    Set OutlookApp = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApp.CreateItem(0)
        
    'Display email and specify To, Subject, etc
    With OutlookMail
        
        .Display
        .To = Email_To
        .CC = Email_CC
        .BCC = Email_BCC
        .Subject = EmailSubject & CurrentMonth
[COLOR=#ff0000][B]        '.Body = Email_body[/B][/COLOR]
[COLOR=#ff0000][B]        .htmlBody = Email_body & "" & SigString[/B][/COLOR]
        .Attachments.Add PDFFile
                
        If DisplayEmail = False Then
            
            .send
            
        End If
        
    End With
End Sub


Function GetBoiler(ByVal sFile As String) As String
'**** Kusleika
    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

thank you
 
Upvote 0
I couldn't see it before unstructured. Obviously, you need the result of GetBoiler(), Signature.
Code:
.htmlBody = Email_body & "" & Signature 'BR inside quotes.
 
Upvote 0
Hi I changed as the as this:

when i execute i can see shows my signature but then disappear and shows this all together not formatting:

i PIERRE-PAUL MCSWEEN , This what I came up with after reconciling the accounts (see attachment) We can do the contra if you agree that the amount of $19,189.85 owes by you and the amount of $4,013.60 owes by TNW Networks. CHARITEL INC. will make a payment for the difference of $16,291.12 payable to TNW NETWORKS Please let me know if it's ok with you to proceed.
C:\Documents and Settings\rossj1\Application Data\Microsoft\Signatures\JROSSI.htm





Code:
'Display email and specify To, Subject, etc    With OutlookMail
        
        .Display
        .To = Email_To
        .CC = Email_CC
        .BCC = Email_BCC
        .Subject = EmailSubject & CurrentMonth
        .Body = Email_body
        .htmlBody = Email_body & "<br>" & SigString
        .Attachments.Add PDFFile
                
        If DisplayEmail = False Then
            
            .send
            
        End If
        
    End With
End Sub

Code:
Function GetBoiler(ByVal sFile As String) As String'**** Kusleika
    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

thank you
 
Upvote 0
thanks so much i got the signature working now

sorry i am not that good in vba,

the only problem i have this is not formatted in the message body, how make separate lines single space right now is like this all scramble:

Hi PIERRE-PAUL MCSWEEN , This what I came up with after reconciling the accounts (see attachment) We can do the contra if you agree that the amount of $19,189.85 owes by you and the amount of $4,013.60 owes by TNW Networks. CHARITEL INC. will make a payment for the difference of $16,291.12 payable to TNW NETWORKS Please let me know if it's ok with you to proceed.


i changed the code to this:
Code:
'.Body = Email_body
        .HTMLBody = Email_body & "<br>" & .HTMLBody

i really appreciate your help

sorry i am not that good

thanks again
 
Upvote 0
thank you so much for all your help, i would not solved it without your help.

i did realize i have to sue "<br>" to get the space.

one question the only thing it changes my font to small any way can fix that.
and is there anyway i can format the subject line with currency format vba?

thanks again
 
Upvote 0
The subject line is not html. Use Format() to format a number to a string value. Or, if using a cell with the number format and value that you want, use the .Text property rather than .Value. .Text returns a string with any number with a number format as a string in that format.

For the font issue, see the html cheat sheet, or others like: https://web.stanford.edu/group/csp/cs21/htmlcheatsheet.pdf.

TIP: You can do that for posts here too.

e.g.
<b><font size=18>Hello World!</font></b>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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