Hi All,
i have to admit that it is a long time since I have been on Tek-tips - used to be a regular user but just getting back into development now after an absence and I am having a problem. I have severl VBScript programs that I am using to update Excel files regularly. Some of these Excel templates have pivot tables. I am updating the "detail" tab in the Excel template and then using the code below (for example) to reset the data source for the pivot table that already exists in the Excel template file:
This works fine when there is only one pivot table in the file. However, i am getting requests now to create multiple pivot tables in files and the code above to reset data source does not appear to work if there are multiple pivots. For example, I have added a second pivot table to an Excel file and updated the code above to the following:
What happens now is that a new empty pivot table gets created in both worksheets and the data source in my two pivot tables are set to only the header row of my detail sheet. Does anyone know why this code would work fine for one pivot but not multiple?
Mighty
i have to admit that it is a long time since I have been on Tek-tips - used to be a regular user but just getting back into development now after an absence and I am having a problem. I have severl VBScript programs that I am using to update Excel files regularly. Some of these Excel templates have pivot tables. I am updating the "detail" tab in the Excel template and then using the code below (for example) to reset the data source for the pivot table that already exists in the Excel template file:
Code:
' Reset the Data Source for the Summary Pivot Table
woFile.WorkSheets("Summary").PivotTables("SummaryTable").PivotSelect "", 0, True
woFile.WorkSheets("Summary").PivotTableWizard 1, "'Work Order Detail'!R3C1:R" & (xlRow-1) & "C24"
This works fine when there is only one pivot table in the file. However, i am getting requests now to create multiple pivot tables in files and the code above to reset data source does not appear to work if there are multiple pivots. For example, I have added a second pivot table to an Excel file and updated the code above to the following:
Code:
' Reset the Data Source for the Summary Pivot Table
woFile.WorkSheets("Summary").PivotTables("SummaryTable").PivotSelect "", 0, True
woFile.WorkSheets("Summary").PivotTableWizard 1, "'Work Order Detail'!R3C1:R" & (xlRow-1) & "C24"
' Reset the Data Source for the Material Variance Pivot Table
woFile.WorkSheets("Material Variance Analysis").PivotTables("MaterialVariance").PivotSelect "", 0, True
woFile.WorkSheets("Material Variance Analysis").PivotTableWizard 1, "'Work Order Detail'!R3C1:R" & (xlRow-1) & "C24"
What happens now is that a new empty pivot table gets created in both worksheets and the data source in my two pivot tables are set to only the header row of my detail sheet. Does anyone know why this code would work fine for one pivot but not multiple?
Mighty