Sub GetPivotSource()
Dim pvt As PivotTable, ServerName As String, CubeName As String
On Error Resume Next
Set pvt = ActiveCell.PivotTable
If Err.Number <> 0 Then
MsgBox "Active cell is not in a pivot table", vbOKOnly, "Pivot Source"
Exit Sub
End If
ServerName = Mid(pvt.PivotCache.Connection, 64, Len(pvt.PivotCache.Connection) - 132)
CubeName = Mid(pvt.PivotCache.Connection, 92, Len(pvt.PivotCache.Connection) - 136)
If ServerName = "" Then
MsgBox "Pivot table data comes from an Excel table", vbInformation
Else
'Show pivot table connection details
MsgBox "Server: " & ServerName & vbCr & "Cube: " & CubeName, vbOKOnly, "Pivot Source"
End If
End Sub