Question : Automate exporting pivot table from access to excel

I am trying to automate in Access 2003 exporting a pivot table to Excel 2003 and retaining the pivot format.

Basically, I am trying to automate the manual process of:
1) opening a query in Access in pivot table view,
2) selecting all (Ctrl A) then
3) pasting into Excel.

I tried the following but it copies the raw data into Excel and loses the pivot formatting:

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "qTest", "c:\test.xls", False

I also tried the following the code (see code section) from another EE question (#21973564) and I'm getting the following errors:

WB.Columns.AutoFit -> Object doesn't support this property or method
WB.Sheets(1).pivottables(1).Refresh ->Unable to get the PivotTables property of the Worksheet class

Are these errors caused by the fact that it was written for excel 2000 and I'm using Excel 2003?

Any suggestions?

Thanks

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qTest", "c:\test.xls", False
    
    'Declare and Start Microsoft Excel 2000.
    Dim AppExcel As Object, WB As Object
    Set AppExcel = CreateObject("Excel.Application")
    Set WB = AppExcel.Workbooks.Open("c:\test.xls")
    AppExcel.Visible = True
    WB.Columns.AutoFit
           
    WB.Sheets(1).pivottables(1).Refresh
           
    'Quit Microsoft Excel and release the object variable.
    AppExcel.Quit
    Set AppExcel = Nothing
    Set WB = Nothing

Answer : Automate exporting pivot table from access to excel

MPH,

May I suggest another path....   Why not use the data from Access as external data to create the Pivot Table in Excel.  You can start from the Excel Data menu and either use the Pivot Table option or use the Import External Data option.    Then build your pivot table in Excel using the Access data instead of trying to move the Access Pivot Table to Excel.  Screen shots of the steps for the two different paths are in the attached PDF files.

In the "Choose Data Source" dialog box, be sure to uncheck the box at the bottom that says:   Use the query wizard to create / edit queries.  

HTH,
Jerry

 
Create Pivot Table from Access Data
 
 
Create Pivot Table from Access Query
 
Random Solutions  
 
programming4us programming4us