How to insert default outlook signature at end of my VBA Macro

tonyjyoo

Board Regular
Joined
Aug 5, 2016
Messages
167
I need help adding my default outlook signature at the end of my VBA.

The following codes I obtained and adjusted from this forum generates my email body to include a table in the body from my excel file:

Code:
Private Sub CommandButton1_Click()
'Send NSCC Deposits email directly from Daily Cash Position - Tony Yoo 2016.
    Dim OutApp As Object, OutMail As Object
    Dim rng As Range
    Dim StrBody As String
    
    StrBody = "Hi:" & "<br>" & "<br>" & "We are expecting the following NSCC deposits."
              
    Application.ScreenUpdating = False
    Set OutApp = CreateObject("Outlook.Application")
    Set rng = Nothing
    On Error Resume Next




    Set rng = Sheets("NSCC Deposit Email").Range("A1:E4").SpecialCells(xlCellTypeVisible)




    On Error GoTo cleanup
 




            Set OutMail = OutApp.CreateItem(0)
            On Error Resume Next
            With OutMail
                .Display
                .To = "Anthony.yoo@jackson.com"
                .CC = "shun.fung@jackson.com; anthony.yoo@jackson.com"
                .Subject = "Today's NSCC Deposits"
                .HTMLBody = StrBody & RangetoHTML(rng)
                             
                .Display  'Or use .Send
            End With
            On Error GoTo 0
            Set OutMail = Nothing




cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True




End Sub

Next, I have this code in a module to put the table in a temp file and place it in my body of my email:

Code:
Function RangetoHTML(rng As Range)
' Tony Yoo 2016 edited from Ron de Bruin
' Working in Office 2000-2016
    Dim fso As Object
    Dim ts As Object
    Dim TempFile As String
    Dim TempWB As Workbook




    TempFile = Environ$("temp") & "\" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"




    'Copy the range and create a new workbook to past the data in
    rng.Copy
    Set TempWB = Workbooks.Add(1)
    With TempWB.Sheets(1)
        .Cells(1).PasteSpecial Paste:=8
        .Cells(1).PasteSpecial xlPasteValues, , False, False
        .Cells(1).PasteSpecial xlPasteFormats, , False, False
        .Cells(1).Select
        Application.CutCopyMode = False
        On Error Resume Next
        .DrawingObjects.Visible = True
        .DrawingObjects.Delete
        On Error GoTo 0
    End With




    'Publish the sheet to a htm file
    With TempWB.PublishObjects.Add( _
         SourceType:=xlSourceRange, _
         Filename:=TempFile, _
         Sheet:=TempWB.Sheets(1).Name, _
         Source:=TempWB.Sheets(1).UsedRange.Address, _
         HtmlType:=xlHtmlStatic)
        .Publish (True)
    End With




    'Read all data from the htm file into RangetoHTML
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
    RangetoHTML = ts.readall
    ts.Close
    RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
                          "align=left x:publishsource=")




    Range("A1:E4").Font.Name = "Cambria"
    
    


    'Close TempWB
    TempWB.Close savechanges:=False




    'Delete the htm file we used in this function
    Kill TempFile




    Set ts = Nothing
    Set fso = Nothing
    Set TempWB = Nothing
End Function

How can I adjust my first VBA to include my outlook signature? When I try editing, the table overrides the outlook default signature.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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