|
-
Jan 2nd, 2006, 11:06 PM
#1
Thread Starter
Junior Member
ACCESS Export PivotTable & Tables to Excel
Hi,
i have generated many tables, and pivot tables in Access. and i want to write codes to export all of them to one single excel sheet.
i have little knowledge about this export function.
may i know how to export pivot tables and normal tables to one single excel file?
thanks in advance.
-
Jan 3rd, 2006, 12:16 AM
#2
Re: ACCESS Export PivotTable & Tables to Excel
If you perform a loop with this you can export all the tables you need to a single excel file but you will have to change sheets target range, adjusting it to compensate for the end of each range of data or just change the destination to a different sheet each time. Then merge the data to a single sheet later if desired.
VB Code:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Table1", "D:\Book1.xls", False, "Sheet1$"
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 3rd, 2006, 12:48 AM
#3
Thread Starter
Junior Member
Re: ACCESS Export PivotTable & Tables to Excel
Thanks. How about exporting Pivot Table?
that code works for normal tables. how about pivottables?
-
Jan 3rd, 2006, 02:04 AM
#4
Re: ACCESS Export PivotTable & Tables to Excel
If the pivit table is saved just like a regular query, then pass its name instead of "Table1".
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 3rd, 2006, 02:46 AM
#5
Thread Starter
Junior Member
Re: ACCESS Export PivotTable & Tables to Excel
pivot table is not a query, it is a form.
so the command doesnt work..
may i know how to export the pivot table to excel file? i want the output just like the way of tables export.
-
Jan 3rd, 2006, 03:06 AM
#6
Re: ACCESS Export PivotTable & Tables to Excel
No, I mean to try passing the pivot table name if that doesnt work then I guess you have to go the route of automating the menu.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 3rd, 2006, 03:18 AM
#7
Re: ACCESS Export PivotTable & Tables to Excel
I wrote a small basic example for you. You well want to add error trapping and testing for menu item existance, etc.
VB Code:
Private Sub ExportPivotTable()
'Add a reference to MS Office xx.0 Object Library
Dim oCBPT As Office.CommandBarPopup
Dim oCBEPT As Office.CommandBarButton
Set oCBPT = Application.CommandBars("Menu Bar").Controls("&PivotTable")
Set oCBEPT = oCBPT.Controls("E&xport to Microsoft Office Excel")
oCBEPT.Execute
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 3rd, 2006, 03:20 AM
#8
Thread Starter
Junior Member
Re: ACCESS Export PivotTable & Tables to Excel
thanks for the reply.
may i know what is the route of automating the menu?
is there any sample command that i can refer to for exporting this pivot table?
there is actually one button on the tool bar. by clicking that, i can export it to a temporary excel file. but i want to achieve this by using vba and specifying the file name and the worksheet name. so my whole process of export can go to one single file.
thanks in advance for all the help.
-
Jan 3rd, 2006, 03:21 AM
#9
Re: ACCESS Export PivotTable & Tables to Excel
Oh, forgot to mention that it was for Access 2003. So if your running a different version or language then the menu captions should be changed to either index numbers or the appropriate context.
I see we posted at almost the same time.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 3rd, 2006, 03:28 AM
#10
Thread Starter
Junior Member
Re: ACCESS Export PivotTable & Tables to Excel
WOW, that is great!
I see that you are executing that button on the menu bar!!
thanks a lot for the help.
juz one further question. cos by doing that, i can only export to a temporary excel file.
how can i specify a file that i wish to export to? because i have other tables and queries to export as well and i want to group them all in one single excel file.
Thanks sincerely for the help!
-
Jan 3rd, 2006, 04:54 AM
#11
Re: ACCESS Export PivotTable & Tables to Excel
Without really getting into some APIs, its not going to be very easy to do it from the current method. Also, I have a few other methods but they have the same issues of not being able to specify a output filename.
VB Code:
'Open your pivot form first
DoCmd.OpenForm "PivitTable1", acFormPivotTable
'Then run either of the two...They output it to Excel a little differently from each other.
DoCmd.RunCommand acCmdPivotTableExportToExcel
'Or
DoCmd.RunCommand acCmdOutputToExcel
I suppose we could just use the Excel Object Model in Access to attach to the exported temp workbook. Then write it into a cummulative Workbook file. a bit messy but I think I can come up with a better way in the morning after I get some sleep.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 8th, 2006, 09:53 AM
#12
Thread Starter
Junior Member
Re: ACCESS Export PivotTable & Tables to Excel
hi, thanks for putting so much effort for helping me..
do u have a good method now? juz to export the pivot table to a specific excel file and specific sheet.
thanks again robdog!!
-
Jan 8th, 2006, 09:59 AM
#13
Re: ACCESS Export PivotTable & Tables to Excel
Sorry, I've been busy but to continue on with my last suggestion would be to use the Excel Object Model and manually export it. But first you need to generate a SQL statement that will be a duplication of your pivot table. Then save it as a query. After you have that you can easily do a .TransferSpreadSheet to a specific workbook and sheet/range.
VB Code:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "PivotQuery1", "D:\Book1.xls", False, "Sheet2$"
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 1st, 2007, 08:40 AM
#14
New Member
Re: ACCESS Export PivotTable & Tables to Excel
When I use this code I get the following...
The command or action 'acCmdPivotTableExportToExcel' isn't available now
Any thoughts?
-
Sep 25th, 2008, 05:30 AM
#15
New Member
Re: ACCESS Export PivotTable & Tables to Excel
Good Morniing
I have been trying to achieve simular but also get the error
The command or action 'acCmdPivotTableExportToExcel' isn't available now
And been batteling to get this to work..
I currently in MS access 2003 have
I have a form called FrmEmployeeCountPivot
And on the above mentioned i have a subform called FrmEmployeeCountPivotSub
The Sub is the Pivot Table
What i am trying to achieve is normally i will click on my pivot table comandbar, on the export to excell. And will work perfectly.
Now Because the sub is on my main form my Pivot Commandbar, does not appear anymore.
I would like to place the command on my main form to allow the user the send the pivot to excell exactly as it happens if i click the send to excel command on my menu..
Is there a way that use the send to excel menu command just behind an normal cmdbutton on my form
I tried using the above
Code:
Private Sub ExportPivotTable()
'Add a reference to MS Office xx.0 Object Library
Dim oCBPT As Office.CommandBarPopup
Dim oCBEPT As Office.CommandBarButton
Set oCBPT = Application.CommandBars("Menu Bar").Controls("&PivotTable")
Set oCBEPT = oCBPT.Controls("E&xport to Microsoft Office Excel") oCBEPT.ExecuteEnd Sub
but only get an error,
is there a way that i can make use of the command on my subform.
Thank you very much in advance for any help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|