Excel 2013工作表激活
我有一个从用户表单激活工作表的问题,相同的代码在Excel 2003到Excel 2010中正常工作,不适用于Excel 2013。
I have an issue with activating a sheet from a user form, the same code works fine in Excel 2003 to Excel 2010, doesn't work with Excel 2013.
这是如何简单地重现这个问题:
This is how to simply reproduce the issue:
有一个工作簿,其中有2个工作表,称为 Sheet1
和 Sheet2
让我们说,在 Sheet1
2按钮:
Have a workbook with 2 worksheets in it, called Sheet1
and Sheet2
let's say, and on Sheet1
2 buttons:
-
点击
Button1
激活Sheet2
工作表使用Macro1
其中有一行:
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.
点击 Button2
a UserForm1
弹出,点击 CommandButton1
调用相同的宏1像这样:
On click of Button2
a UserForm1
pops up and on click of CommandButton1
call same Macro1 like this:
Unload Me
Macro1
Sheet2
工作表已激活,但如果我编辑其中的数据,它实际上更新了Sheet1中的对应单元格,如果我点击 Sheet1
我可以看到在那里输入的数据!
the Sheet2
worksheet is activated, sort of, but if I edit data in it, it actually updates corresponding cells in Sheet1, if I click on Sheet1
I can see data entered in there!
点击 Sheet2
工作表正确激活 Sheet2
表。
Clicking back to Sheet2
worksheet activates the Sheet2
sheet properly.
有没有人看到这样的行为?如果是,是否有任何编码解决方法正确激活 Sheet2
?
Has anyone seen such behaviour? If yes, are there any coding workarounds to properly activate Sheet2
?
根据Profex的回答,我能够在Excel 2013中重现错误。解决问题的解决方法是使我的用户界面无模式。
I was able to reproduce the error in Excel 2013 as per Profex's answer. A workaround that solved the issue for me was to make my userform modeless.
userform1.show vbModeless
我明白,如果您需要模态表单,此解决方法将不会有帮助,但希望可以保存下一个人一段时间。
I understand that this workaround won't be helpful if you require a modal form, but hopefully it will save the next person some time.