It looks like that there is no pivottable called "Pivottable2" on that
activesheet.
If you're creating a single pivottable on each sheet, maybe...
ActiveSheet.PivotTables(1).AddFields RowFields:="dosmoyr", _
ColumnFields:="transmoyr", PageFields:="facilityid"
"Pete Straman via OfficeKB.com" wrote:
I recorded a macro that created two pivot tables from an external DB. The
first time it runs in "Book1" ok. The second time the statement below
causes a run time error. I have to close and re-open excel to make it run
all the way through on another database. What can I do to make it run in
"Book2" etc. without having to close and re-open excel.
'******* Run time error 1004 unable to get the Pivot Tables property of the
worksheet class
ActiveSheet.PivotTables("PivotTable2").AddFields RowFields:="dosmoyr", _
ColumnFields:="transmoyr", PageFields:="facilityid"
Pete Straman
--
Message posted via http://www.officekb.com
--
Dave Peterson