我有一个与我的“简介”表相关联的宏 . 它由单元格更改触发,然后调用第二个宏来操作另一个工作表“TimeInLibraryData” . 这很简单:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheets("TimeInLibraryData").Visible = True
Sheets("TimeInLibraryData").Activate
MsgBox "The name of the active sheet is " & ActiveSheet.Name
Call CreateTimeLine.CreateTimeLine1(1)
结束子
Public Sub CreateTimeLine1(PickSingleLib As Long)
Sheets("TimeInLibraryData").Activate
MsgBox "The name of the active sheet is " & ActiveSheet.Name
结束子
您可以看到我正在输出活动工作表名称 . 问题是,在显示的两个地方,我看到ActiveSheet是“简介”表,它应该是“TimeInLibraryData”
该应用程序是用Excel 2010编写的,我刚刚更新到Excel 2016,可以看到问题所在 .
在Excel 2016中运行,如果我在正常运行时访问CreateTimeLine1宏,它可以工作 . 我只看到在更改“简介”工作表后调用宏时出现问题 .
我在VBA 2016中创建了一个减少的示例,发现它按预期工作 . 我还在Excel 2010中创建了一个简单的示例,并在Excel 2016中运行它也起作用 .
所以 - 我有一个非常令人困惑的情况与运行一组用Excel / VBA 2010编写的宏在Excel / VBA 2016中无法正常工作相关联
1 回答
我'm using Excel 2016 with the latest patches and can' t重现了这种行为 . 你应该在
Application.EnableEvents = False
和Application.EnableEvents = True
之间将你的电话夹在Sheets("TimeInLibraryData").Activate
之间,以确保没有其他事件处理程序捕获你的线路将触发的Worksheet_Activate
事件 .