简体   繁体   English

查找是否使用VBA或用户打开了工作簿

[英]Find if workbook was opened using VBA or by user

I have a macro workbook Excel 2007 with a workbook open event. 我有一个带有工作簿打开事件的宏工作簿Excel 2007。 Inside the workbook open event is it possible for me find if the workbook was opened by the user from windows or from another workbook using vba... 在工作簿打开事件中,我可以发现用户是从Windows还是使用vba从另一个工作簿打开了工作簿...

I am not sure if it fits your needs, but you can open a workbook in your VBA code without firing the events: 我不确定它是否适合您的需求,但您可以在VBA代码中打开工作簿而不触发事件:

'Disable Events.
Application.EnableEvents = False

'Open your book.
Workbooks.open(Filename)

'Enable Events.
Application.EnableEvents = True

If this suits your purpose: 如果这符合您的目的:

When opening with vba, change the name of the workbook before opening. 使用vba打开时,请在打开前更改工作簿的名称。 Then change it back when done. 然后在完成后将其更改回去。 Workbook_Open procedure just needs to check for the name of the workbook it is in. Workbook_Open过程仅需要检查它所在的工作簿的名称。

To change the name of the workbook 更改工作簿的名称

you can open it, then use SaveAs method to close it again with the new name 您可以将其打开,然后使用SaveAs方法以新名称再次将其关闭

use the Shell function 使用Shell函数

use a Microsoft Scripting Runtime object. 使用Microsoft脚本运行时对象。

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

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