在没有执行excel的情况下,Workbook_Open()不会执行 [英] Workbook_Open() is not executed with excel already running

查看:1396
本文介绍了在没有执行excel的情况下,Workbook_Open()不会执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用excel 2007我编写了一个宏,我想从Workbook_Open()调用开始(放在thisWorkbook中)。

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

这样工作正常只要这是一个新的excel会话,因此它将与xlsm-file / I一起启动excel并加载该文件。

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.

但是一旦excel已经运行,不执行Workbook_Open()函数。宏必须在加载工作簿后手动启动。

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.

要澄清:即使没有其他工作簿打开,也会发生这种情况excel,所以我相信没有其他的计算可能会干扰Workbook_Open()调用(大部分时间提出)。

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).

(问题似乎存在于excel 2003年:
Excel工作簿打开事件宏不总是运行

(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

推荐答案

你可以创建一个全局bool变量,并在workbook_open中设置一个值为true。

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

在验证变量值

'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

[]的

这篇关于在没有执行excel的情况下,Workbook_Open()不会执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆