There's no such thing as a stupid question, but they're the easiest to answer.


Search Search
Search for:
Tech Support Guy > > >

Access 2007 VBA Function DoCmd.RunCommand acCmdPivotExportToExcel


mariaa33's Avatar
mariaa33 mariaa33 is offline
Member with 156 posts.
Join Date: Aug 2008
Experience: Beginner+
14-Mar-2012, 10:37 AM #1
Access 2007 VBA Function DoCmd.RunCommand acCmdPivotExportToExcel
I have a vba function that I converted from a macro but the DoCmd.RunCommand acCmdPivotExportToExcel errors out in the function with runtime error 2501 - The RunCommand action was cancelled. Is there a different way I should be doing this? I am doing a few other things first and then it opens the query but stops. I need to export the pivot table to excel and keep the format of the pivot and I am showing only the top 10.

DoCmd.OpenQuery "CS Top 10 Query", acViewPivotTable, acEdit
DoCmd.RunCommand acCmdPivotExportToExcel
OBP's Avatar
OBP OBP is offline OBP is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 18,827 posts.
Join Date: Mar 2005
Location: UK
14-Mar-2012, 01:38 PM #2
I have never used that command, but I have seen it helps if you open Excel first
Set xlApp = CreateObject("Excel.Application")

xlApp.Visible = True
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

You Are Using: Server ID
Trusted Website Back to the Top ↑