Workbook_Open() is not executed with excel already running

雨燕双飞 提交于 2019-12-11 08:38:48

问题


using excel 2007 I programmed a macro, which I would like to start with the Workbook_Open() call (placed in "thisWorkbook").

This works fine as long as this is a new "excel-session", therefore it is started together with the xlsm-file / I start excel and load the file.

However as soon as excel is already running, the Workbook_Open() function is not executed. The macro otherwise still works fine, as soon as I start it manually after the workbook has been loaded.

To clarify: This happens even if no other workbook is open, just excel, so I am convinced that no other calculation could interfere with the Workbook_Open() call (as proposed most of the time).

(the problem seems to exist for excel 2003 too: Excel Workbook Open Event macro doesn't always run)

I would be grateful for any hints how to call my macro in any case! (As my users most of the time already have excel up and running when starting my file) Thanks


回答1:


You can create a global bool variable, and set a value with true in workbook_open .

And after you verify value of variable

'In Module
Global BoolCheck As Boolean


Sub CheckValue()
'Verify if Workbook_Open Event is called
If BoolCheck = False Then
    'case not call the
    ActiveWorkbook.Workbook_Open
End If
End Sub

'in Workbook Object
Public Sub Workbook_Open()
    BoolCheck = True
End Sub

[]´s



来源:https://stackoverflow.com/questions/9006902/workbook-open-is-not-executed-with-excel-already-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!