Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 30097

VBA In Excel to Create Email with Table and Signature

$
0
0

I'm trying to create a custom email when button is clicked in Excel. All users have Outlook. In the body of the email I want to include a portion of a spreadsheet that is already formatted.

I can get the information in there but I can't get the order right in the body. That is the text, then formatted table THEN signature.

The example below puts the formatted table BELOW but I want the signature to be the last thing.

Any help would be greatly appreciated.

Sub SendUpdateEmail()

Dim outlook As Object
Dim newEmail As Object
Dim xInspect As Object
Dim pageEditor As Object
Dim EmailTo As String
Dim EmailCC As String
Dim UpdateDate As String
Dim Location As String
Dim strSig As String


' Set Outlook object
Set outlook = CreateObject("Outlook.Application")

' Set Email Mail Object
Set newEmail = outlook.CreateItem(0)

' Set Inspect Object
Set xInspect = newEmail.GetInspector

' Set Page Editor Object
Set pageEditor = xInspect.WordEditor

' Set Email To
EmailTo = Worksheets("Project Summary").Cells(15, "F").Value

' Set Email CC
EmailCC = Worksheets("Project Summary").Cells(16, "F").Value

' Set Update date
UpdateDate = Worksheets("OUTPUT - Daily Field Ticket").Cells(7, "B").Value

' Set Location
Location = Worksheets("OUTPUT - Daily Field Ticket").Cells(5, "B").Value



With newEmail
.To = EmailTo
.CC = EmailCC
.BCC = ""
.Subject = "UPDATE | " + Location + " | " + UpdateDate

'DO NOT REMOVE - THIS MUST BE VISIBLE FIRST TO GET THE DEFAULT SIGNATURE
.Display

'GET THE HTML CODE FROM THE SIGNATURE
strSig = .HTMLBody

.HTMLBody = "Hello,"& "<br>"& "<br>"& "Please see attached the Daily Field Ticket for " + Location 
+ " for " + UpdateDate + "." + strSig


Sheet1.Range("A28:F35").Copy

pageEditor.Application.Selection.Start = Len(.Body)
pageEditor.Application.Selection.End = pageEditor.Application.Selection.Start
pageEditor.Application.Selection.PasteAndFormat (wdFormatPlainText)

Set pageEditor = Nothing
Set xInspect = Nothing

End With

Set newEmail = Nothing
Set outlook = Nothing

End Sub

Viewing all articles
Browse latest Browse all 30097

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>