Febinedwards123
New Member
Can someone please help me with what is wrong with the below code ? I don't get any error but the problem is the range / table from intended worksheet is not getting copied to the email body.
>>> use code - tags <<<
>>> use code - tags <<<
Code:
Private Sub Workbook_Open()
'send automated email when workbook is open
Dim olkObj As Object
Dim olkEm As Object
Dim strbody As String
Dim sh As Worksheet
Set sh= ThisWorkbook.sheets("Payments Due")
Dim Lr as integer
Lr = sh.range("A" & Application.Rows.count).End(x1Up).Row
Sh.Range("A1:C" & Lr).select
Set olkObj = CreateObject("Outlook.Application")
Set olkEm = olkObj.CreateItem(0)
strbody = "Hi there" & vbNewLine & vbNewLine & _
ThisWorkbook.Name & vbNewLine & _
"was opened by" & vbNewLine & _
Environ("username")
On Error Resume Next
With olkEm
.To = ""
.CC = ""
.BCC = ""
.Subject = "Payments Due"
.Body = strbody
.Send
End With
On Error GoTo 0
Set olkEm = Nothing
Set olkObj = Nothing
End Sub
Last edited by a moderator: