VBA不允许运行Auto_Open [英] VBA that doesn't allow Auto_Open to Run

查看:75
本文介绍了VBA不允许运行Auto_Open的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个电子表格.为了简化示例代码,我们将使用Book1和Book2.Book1包含一张纸,Book2包含两张纸.

I have two spreadsheets. For ease of example code we will use Book1 and Book2. Book1 contains one sheet and Book2 contains two sheets.

Book2包含以下代码:

Book2 contains the code:

Function Auto_Open()
sheets(1).range("B1:B50").formula="=vlookup(A1,Sheet2!A1:C50,3,False)"
End Function

第一本书包含如下代码:

Book one contains code like the following:

Function UpdateBook()
Workbooks("Desktop\Book2.xls").open
workbooks("Book2").sheets(2).values=workbooks("Book1").sheets(1).values
workbooks("Book2").close
End Function

由于要打开Book2中的Book1中的功能,因此我想阻止它在Book2上运行时自动运行.使用一段VBA代码可以做到这一点吗?

I want to prevent the Auto_Open on Book2 from running when it opens as a result of the function in Book1 opening Book2. Is this possible to do using a segment of VBA code?

推荐答案

在打开book2之前禁用事件:

Disable Events before open book2:

Application.EnableEvents = False
Workbooks("Desktop\Book2.xls").open
...
Application.EnableEvents = True

这篇关于VBA不允许运行Auto_Open的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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