简体   繁体   中英

Updating excel tables and pivot tables from within access

I am running an update from within an Access 2010 database using VBA code. The update needs to update some tables by calling queries. This part works fine. I need to call a VBA macro in an Excel workbook to update the tables and pivot tables (which happen to get their data from the same Access database from which the VBA code is executing).

I get an error on the first line of code in the Excel workbook. The first line simply is to select the approprite worksheet. I know I am over complicating this. But the whole reason is that I have to update the data since the code in the Access macro takes the summary worksheet and spits it out as html in a outlook mail message (which works beautifully).

Should I just take the code for calling the refresh and add the code for the html email to it? Calling the Access stuff first, exit Access, then call the function by calling for Excel to open, do its thing, then exit Excel?

A few options here, since I don't know your exact setup or the whys and wherefors of how things are being done:

  • Try setting your excel pivottables to get their data by linking directly to the access file, instead of copying the data from it. There's an option in pivot table settings to "refresh data on open."

  • Check out the Import External Data wizard in the Data menu of Excel. This will create a worksheet that just links to data. This also has a "refresh data on open" option. Then you can base your pivot tables on this, and have them refresh on open as well. I think the first option is better, however :D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM