I am trying to write a Macro that goes through all of the Tables in a workbook and then adds the name of each table in the form of "TableName[#All]" to an array.
See incomplete code below
Sub NewShopPage()
'
' Macro that creates a duplicate sheet from a hidden template
' searches for every table in the workbook and then adds them to the
' PivotTableWizard.
'
Dim NewShop As Variant
NewShop = InputBox("What Shop are you creating a new estimate sheet for? (example: Shop 18)")
NewShop = Replace(NewShop, " ", "_")
Sheets("CE_Template").Copy After:=Sheets("Project Estimator")
ActiveSheet.Name = NewShop
ActiveSheet.ListObjects(1).Name = NewShop
Sheets("Project Estimator").Select
ActiveSheet.ListObjects(1).Select
Dim MyArray As Variant
'HELP NEEDED HERE:
'For each [Table] in [workbook]
' Add TableName + "[#All]" to MyArray
'Next
ActiveSheet.PivotTableWizard SourceType:=xlConsolidation, SourceData:=MyArray
End Sub
I have only come to the conclusion that it must operate this way because if a user adds a worksheet then later deletes it, the PivotTableWizard errors out.
I am not sure if doing it this way each time will erase the formatting the PivotTable has.