简体   繁体   English

在Access中更新Excel表和数据透视表

[英]Updating excel tables and pivot tables from within access

I am running an update from within an Access 2010 database using VBA code. 我正在使用VBA代码从Access 2010数据库中运行更新。 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). 我需要在Excel工作簿中调用VBA宏来更新表和数据透视表(它们恰巧是从执行VBA代码的同一个Access数据库中获取数据的)。

I get an error on the first line of code in the Excel workbook. 我在Excel工作簿的第一行代码中收到错误。 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). 但是整个原因是我必须更新数据,因为Access宏中的代码将使用摘要工作表并将其作为html发送到Outlook邮件消息中(效果很好)。

Should I just take the code for calling the refresh and add the code for the html email to it? 我应该只使用调用刷新的代码并将HTML电子邮件的代码添加到其中吗? Calling the Access stuff first, exit Access, then call the function by calling for Excel to open, do its thing, then exit Excel? 首先调用Access东西,退出Access,然后通过调用Excel来打开函数来调用函数,执行该操作,然后退出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. 尝试通过直接链接到访问文件来设置excel数据透视表以获取其数据,而不是从中复制数据。 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. 在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 我认为第一种选择更好,但是:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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