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:
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:
How can I adjust my first VBA to include my outlook signature? When I try editing, the table overrides the outlook default signature.
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.