Hello all and thanks in advance!
I have a need to convert the following code to a late binding format so I can distribute to non excel people.
I am looking to make this code work without the references
I have tried, but I get stuck with the inspector and the word part.
Thanks for the help!
Kind regards,
Marc
I have a need to convert the following code to a late binding format so I can distribute to non excel people.
I am looking to make this code work without the references
I have tried, but I get stuck with the inspector and the word part.
Thanks for the help!
Kind regards,
Marc
Code:
Option Explicit
Sub sendEmailUsingWordEditor()
'requires MicrosoftOutlook xx Library reference
'requires MicrosoftWord xx Library reference
'this creates an email with full html // an almost exact copy of a range on an excel sheet
'borrowed from https://www.youtube.com/watch?v=f8s-jY9y220
'Excel VBA Introduction Part 29.1 - Creating Outlook Emails - WiseOwlTutorials
Dim olApp As Outlook.Application
Dim olEmail As Outlook.MailItem
Dim olInsp As Outlook.Inspector
Dim wDoc As Word.Document
Dim strGreeting As String
Dim lastRow As Integer
'sets header
strGreeting = "Dear John," & vbNewLine
'sets email
Set olApp = New Outlook.Application
Set olEmail = olApp.CreateItem(olMailItem)
With olEmail
.BodyFormat = olFormatRichText
.Display
.SentOnBehalfOfName = "department@company.com"
.To = "john.doe@abccompany.com"
.Subject = "Sending this cool email with colors and html"
'this allows us to copy/paste the Excel data
'this will copy range a1 to g lastrow into the email under the greeting
Set olInsp = .GetInspector
Set wDoc = olInsp.WordEditor
wDoc.Range.InsertBefore strGreeting
lastRow = ActiveSheet.Range("A999").End(xlUp).Row
ActiveSheet.Range("A1:G" & lastRow + 5).Copy
wDoc.Range(Len(strGreeting), Len(strGreeting)).Paste
Application.CutCopyMode = False
End With
End Sub
Last edited: