aspiringnerd
New Member
- Joined
- Apr 22, 2022
- Messages
- 39
- Office Version
- 365
- Platform
- Windows
I get the error at the following line
I declared table1 as a range and then set it equal to a dynamic range but I'm getting the error.
VBA Code:
Set table1 = .Range(Cells(1, 1), Cells(count_row, count_col))
VBA Code:
Sub Email_range()
Dim OutApp As Object
Dim OutMail As Object
Dim count_row, count_col As Integer
Dim table1 As Range
Dim table2 As Range
Dim str1, str2, str3 As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With Sheets("Sheet1")
count_row = WorksheetFunction.CountA(.Range("A1", .Range("A1").End(xlDown)))
count_col = WorksheetFunction.CountA(.Range("A1", .Range("A1").End(xlToRight)))
Set table1 = .Range(Cells(1, 1), Cells(count_row, count_col))
End With
With Sheets("Sheet2")
count_row = WorksheetFunction.CountA(.Range("A1", .Range("A1").End(xlDown)))
count_col = WorksheetFunction.CountA(.Range("A1", .Range("A1").End(xlToRight)))
Set table2 = .Range(Cells(1, 1), Cells(count_row, count_col))
End With
str1 = "<BODY STYLE = font-size12pt/font-family:Calibri>" & "Good morning,<br>”"
str2 = "<br>Please see below.<br>"
str3 = "<br>Best regards."
On Error Resume Next
With OutMail
.to = "thisistest@test.com"
.CC = " "
.Subject = "Daily Report"
.Display
.HTMLBody = str1 & RangetoHTML(table2) & str2 & RangetoHTML(table1) & .HTMLBody
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub