【发布时间】:2014-09-19 23:45:44
【问题描述】:
我想要一个对当前工作表执行某些操作的无模型表单。 当我在定义表单的同一工作簿中的工作表上使用它时,一切正常。 (ActiveSheet 代表当前工作表)。
当我在有不同的活动工作簿时尝试使用表单时会出现问题,当我单击一个表单时,它会立即激活定义它的工作簿并且 ActiveSheet 不再适用于我。它的行为很奇怪:
dim ws as worksheet
set ws=ActiveSheet
给我“类型不匹配”
debug.print ActiveSheet.Name ' prints the name of the original worksheet
debug.print ActiveSheet.Parent.Name ' prints the name of the workbook where form is defined
这是 Excel 2013。 我想我可以在以前的版本中做到这一点。这个能力是不是没了?
【问题讨论】:
-
根据this,ActiveSheet 返回一个
object。您可能需要演员阵容。 -
试试
Application.ActiveSheet -
不要使用
ActiveSheet。请改用Sheet1或Sheets("Sheet1")。当工作表处于非活动状态时会发生什么?