BrotherDude
Board Regular
- Joined
- Sep 11, 2013
- Messages
- 50
Hello all,
I am trying to automate a report to send tables via outlook. I am summarizing the data in a Pivot however I am getting an error as soon as it starts the first loop. I think is may be some kind of sheet naming or activation error but I'm really not sure any ideas? I've bolded the spot of the error below.
Sub WeeklyReport()
Dim rng As Range
Dim Sxbdy As Range
Dim OutApp As Object
Dim OutMail As Object
'Dim Lastrows As Range
'Sets loop
records = Application.CountA(Sheets("Pivot").Range("B:B"))
For r = 2 To records
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Cells(r, 2).ShowDetail = True
ActiveSheet.ListObjects(1).TableStyle = "TableStyleLight8"
ActiveSheet.ListObjects(1).ShowTableStyleColumnStripes = True
'Chose which collumns to include & format
Columns("A:K").EntireColumn.AutoFit
ActiveSheet.ListObjects(1).Unlist
Lastrows = Range("A" & Rows.Count).End(xlUp).Row
'Columns("D:I").NumberFormat = "_(#,##0.00_);_((#,##0.00);_(""-""_)"
Range("A:C").HorizontalAlignment = xlLeft
Cells.Font.Size = 8.5
Cells(1, 3).Select
Columns("A:K").EntireColumn.AutoFit
Set Sxbdy = Range("A1:K" & Lastrows)
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Management Information"
.HTMLBody = RangetoHTML(Sxbdy)
.Send
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
'Set Lastrows = Nothing
Next r
End Sub
Thank you in advance
I am trying to automate a report to send tables via outlook. I am summarizing the data in a Pivot however I am getting an error as soon as it starts the first loop. I think is may be some kind of sheet naming or activation error but I'm really not sure any ideas? I've bolded the spot of the error below.
Sub WeeklyReport()
Dim rng As Range
Dim Sxbdy As Range
Dim OutApp As Object
Dim OutMail As Object
'Dim Lastrows As Range
'Sets loop
records = Application.CountA(Sheets("Pivot").Range("B:B"))
For r = 2 To records
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Cells(r, 2).ShowDetail = True
ActiveSheet.ListObjects(1).TableStyle = "TableStyleLight8"
ActiveSheet.ListObjects(1).ShowTableStyleColumnStripes = True
'Chose which collumns to include & format
Columns("A:K").EntireColumn.AutoFit
ActiveSheet.ListObjects(1).Unlist
Lastrows = Range("A" & Rows.Count).End(xlUp).Row
'Columns("D:I").NumberFormat = "_(#,##0.00_);_((#,##0.00);_(""-""_)"
Range("A:C").HorizontalAlignment = xlLeft
Cells.Font.Size = 8.5
Cells(1, 3).Select
Columns("A:K").EntireColumn.AutoFit
Set Sxbdy = Range("A1:K" & Lastrows)
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Management Information"
.HTMLBody = RangetoHTML(Sxbdy)
.Send
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
'Set Lastrows = Nothing
Next r
End Sub
Thank you in advance