Sub PivotSource ()
Dim xlWkBk As Object Forms![DVS - YTD - UCR Part I by PSA (3YRS,M)].olePivotTable.Action = acOLEActivate
Set xlWkBk = Forms![DVS - YTD - UCR Part I by PSA (3YRS,M)].olePivotTable.Object.Application.Workbooks(1)
MsgBox xlWkBk.PivotCaches(1).CommandText
Debug.Print xlWkBk.PivotCaches(1).CommandText
End Sub
I didn't say that. I said, rename the object, i.e. the OLE object not the form. Put the old form name back as it is.Thank you for your time. I renamed the form to olePivotTable by going to Sheet property / Name.
Sub PivotSource ()
Dim xlWkBk As Object, frm As Form
Set frm = Forms![DVS - YTD - UCR Part I by PSA (3YRS,M)]
Set xlWkBk = frm.olePivotTable.Object.Application.Workbooks(1)
MsgBox xlWkBk.PivotCaches(1).CommandText
Debug.Print xlWkBk.PivotCaches(1).CommandText
End Sub
Set xlWkBk = frm.olePivotTable.Object.Application.Workbooks(1)
Sub GetPivotSource()
Dim xlApp As Object
Dim xlWkBk As Object
Dim frm As Form
Set frm = Forms![DVS - YTD - UCR Part I by PSA (3YRS,M)]
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlApp = frm.olePivotTable.Object.Application
Set xlWkBk = xlApp.Workbooks(1)
MsgBox xlWkBk.PivotCaches(1).CommandText
Debug.Print xlWkBk.PivotCaches(1).CommandText
End Sub