Hi Guys,
I have code for click event on an Access form that opens an Excel file, refreshes data of a pivot table on the active worksheet and then filters records based on a criteria. Everything works fine if I open Access for the first time and click the button to run my code. However, if I close the Excel file and then reclick the button that runs my code I receive a debug message saying "Run-time error 91, Object variable or with block not set." Here is my code. The code halts at: Set pt = ActiveSheet.Piv otTables("Pivot Table3"). Any help would be greatly appreciated. Thanks!
I have code for click event on an Access form that opens an Excel file, refreshes data of a pivot table on the active worksheet and then filters records based on a criteria. Everything works fine if I open Access for the first time and click the button to run my code. However, if I close the Excel file and then reclick the button that runs my code I receive a debug message saying "Run-time error 91, Object variable or with block not set." Here is my code. The code halts at: Set pt = ActiveSheet.Piv otTables("Pivot Table3"). Any help would be greatly appreciated. Thanks!
Code:
Dim appExcel As Excel.Application
Dim wkb As Excel.Workbook
Dim strFile As String
Dim pt As PivotTable
Set appExcel = New Excel.Application
strFile = "\\pwrutc\wrkgrp\Operations\Facilities Plant Operations\CapitalPlanningDB\TomTest.xls"
Set wkb = appExcel.Workbooks.Open(strFile)
appExcel.Visible = True 'Do something with worksheet
Set pt = ActiveSheet.PivotTables("PivotTable3")
pt.RefreshTable
ActiveSheet.PivotTables("PivotTable3").PivotFields("CBR/130Y").CurrentPage = "2007045"
Set wkb = Nothing
Set appExcel = Nothing
Set pt = Nothing
Comment