I AM TRYING TO PASTE A NAMED PIVOT TABLE (ENTIRE TABLE) AS A HTML TABLE IN A EMAIL. I CAN ONLY GET A RANGE TO PASTE IN THE EMAIL. DOES ANYONE KNOW HOW TO SELECT A NAMES PIVOT TABLE USING RON DE BRUIN CODE FOR EMAILING.
I AM ALSO WANT A RANGE OF CELLS TO BE INCLUDED BELOW THE PIVOT TABLE. ANY IDEAS.
I AM ALSO WANT A RANGE OF CELLS TO BE INCLUDED BELOW THE PIVOT TABLE. ANY IDEAS.
Code:
Sub Mail_Selection_Range_Outlook_Body()
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
'Don't forget to copy the function RangetoHTML in the module.
'Working in Excel 2000-2013
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Dim StrBody As String
Set rng = Nothing
On Error Resume Next
'Only the visible cells in the selection
Set rng = Selection.SpecialCells(xlCellTypeVisible)
'You can also use a fixed range if you want
[U][/U][B]Set rng = Sheets("Anderson").Range("A3:I125").Value[/B]
On Error GoTo 0
If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "scott.thompson@EMAIL.com"
.CC = ""
.BCC = ""
.Subject = Sheets("Anderson").Range("AA5").Value
.HTMLBody = RangetoHTML(rng)
'& StrBody
'.StrBody = Sheets("Anderson").Range("AA6:AA112").SpecialCells(xlCellTypeVisible)
.Send 'or use .Display
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub