我有一个问题,需要在用户表单中激活工作表,相同的代码在Excel 2003到Excel 2010中运行良好,但在Excel 2013中无法正常工作。
以下是简单复现此问题的方法:
创建一个包含两个名为Sheet1
和Sheet2
的工作表的工作簿,并在Sheet1
上添加两个按钮:
On click of
Button1
activatesSheet2
worksheet using aMacro1
with 1 line in it:ThisWorkbook.Sheets("Sheet2").Select
and I can edit data from it fine.
On click of
Button2
aUserForm1
pops up and on click ofCommandButton1
call same Macro1 like this:Unload Me Macro1
the
Sheet2
worksheet is activated, sort of, but if I edit data in it, it actually updates corresponding cells in Sheet1, if I click onSheet1
I can see data entered in there!
点击返回到Sheet2
工作表会正确激活Sheet2
工作表。
有人遇到过这样的行为吗?如果有,是否有编码解决方案可以正确激活Sheet2
?
application.screenupdating = false
。同时,你必须像这样调用用户窗体userform.show False
。检查工作表名称,并确保有on error goto 0
。 - Patrick Lepelletier