[英]Workbook_Open event erroneously triggered when linking to xlsm workbook
I am running a [Edit] read-only (3rd party!) [/Edit] SQL database, an xlsm, an xls (saved copy of the xlsm, just without macros), and an mdb (Access database). 我正在运行[编辑]只读(第三方!)[/ Edit] SQL数据库,xlsm,xls(xlsm的已保存副本,没有宏)和mdb(Access数据库)。
They are linked as follows: 它们的链接如下:
Since the code modules still exist at that moment (the workbook is not yet closed), I can open the Access mdb and refresh the Excel link to a table in the 2003 data, then close Access. 由于那时代码模块仍然存在(工作簿尚未关闭),因此我可以打开Access mdb并刷新到2003数据中的表的Excel链接,然后关闭Access。
I then reopen the xlsm, triggering a new Application.Ontime instance. 然后,我重新打开xlsm,触发一个新的Application.Ontime实例。
This sequence runs during office hours and at the first run after 5pm sets a timer to start the process again in the morning. 此序列在办公时间运行,在下午5点之后的第一次运行中,设置了一个计时器,以在早晨再次启动该过程。
My problem is whenever I open a file with a connection or link to the xlsm, the Workbook_Open event seems to trigger and I end up with the 2003 xls open on the 'client' computers. 我的问题是,每当我打开一个具有xlsm的连接或链接的文件时,Workbook_Open事件似乎都会触发,最后我在“客户端”计算机上打开了2003 xls。 I know it's not just a leftover Application.OnTime on mine (the PC I originally created the files on) because now it's in use and other clients who have never opened the xlsm get the 2003 file randomly popping up when they're using Excel. 我知道这不仅仅是我剩下的Application.OnTime(我最初在上面创建文件的PC),因为现在它正在使用中,而其他从未打开过xlsm的客户端在使用Excel时会随机弹出2003文件。
If that's not enough to trigger someone to know what's going on, I'll happily post code - but I am hoping someone has seen this before or knows of this rookie mistake and can simply give me a line I'm missing. 如果那还不足以触发某人知道发生了什么,我会很高兴地发布代码-但我希望有人以前见过此消息或知道此菜鸟错误,并可以给我一条我缺少的行。
Thanks so much for your help! 非常感谢你的帮助!
I would think the reason the XLS pops up on your clients is because Excel has to open the linked XLSM in order to access the data, and as such, Workbook_Open
gets triggered. 我认为XLS在您的客户端上弹出的原因是Excel必须打开链接的XLSM才能访问数据,并因此触发Workbook_Open
。
A few alternatives to the suggestions you have in the comments; 您可以在注释中提供一些建议;
Environ("Username")
before executing Application.OnTime
so that it will only run if the file is opened by specific users. 在执行Application.OnTime
之前,请检查Environ("Username")
,以使其仅在特定用户打开文件时才运行。 Global
-scope variable, and then have the XLSM check this variable before running Application.OnTime
. 使用启动程序文件以“管理员模式”打开XLSM-您可以通过使用启动程序文件设置Global
scope变量来执行此操作,然后让XLSM在运行Application.OnTime
之前检查此变量。 C:\\Data\\xlsm-enabler.txt
or whatever works, and only run the relevant macro if the file exists. 例如,XLSM可以查找C:\\Data\\xlsm-enabler.txt
或任何可行的方法,并且仅在文件存在时运行相关的宏。 SaveSetting
to set a registry key on the "admin" machine(s) and check against this inside the XLSM. 与上述类似,使用SaveSetting
在“ admin”计算机上设置注册表项,并在XLSM中对此进行检查。 An easy solution would be to have all other files link to the .xls
file, instead of the .xlsm
macro enabled file. 一个简单的解决方案是将所有其他文件链接到.xls
文件,而不是启用.xlsm
宏的文件。 Downside to this approach would be that you have to (manually) update all your references. 这种方法的缺点是您必须(手动)更新所有参考。
It would be way easier to do everything in Access. 在Access中执行所有操作会更容易。 Then if you need to represent the data in Excel you can have a Workbook with a link to the Access table. 然后,如果您需要在Excel中表示数据,则可以有一个带有访问表链接的工作簿。 This removes a step and it uses the right tool for the job. 这消除了一个步骤,并且使用了正确的工具进行作业。 Access is for linking to database tables. 访问用于链接到数据库表。 Excel is for processing data views. Excel用于处理数据视图。
SQL > Access > Excel
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.