[英]Excel VBA - if activeworkbook is thisworkbook
I have a macro in a workbook assigned to shortcut CTRL + S
(intentionally), which runs a few things before saving the file, however this shortcut is picked up by any other document whilst this one is open. 我在工作簿中有一个宏(故意地)分配给快捷键
CTRL + S
,该宏在保存文件之前会运行一些操作,但是打开此快捷键时,任何其他文档都会使用此快捷键。
Can you directly test if the Activeworkbook
= ThisWorkbook
so this is ignore when using any other workbooks? 您能否直接测试
Activeworkbook
= ThisWorkbook
以便在使用任何其他工作簿时将其忽略?
Sub ShowHiddenSheets()
If ThisWorkbook = ActiveWorkbook Then
`code stuff
End If
Exit Sub
Rather than doing any checks, Add this to the required workbook: 无需进行任何检查,而是将其添加到所需的工作簿中:
dim w as Workbook
set w = ThisWorkbook
then within your modules, reference w. 然后在您的模块中,参考w。 For example:
例如:
with w.sheets("Sheets1")
This will ensure the macro only runs in that specific workbook, and not the others 这将确保宏仅在该特定工作簿中运行,而不在其他工作簿中运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.