vba 代码只隐藏一个工作簿而不是隐藏所有当前打开的工作簿
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23602997/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Code to hide only one workbook instead of hiding all currently open workbooks
提问by Hush
I usually have multiple workbooks open and on one workbook, I have a VBA code that hides the workbook and shows a UserForm. But when I open that workbook, all of my workbooks that are currently opened will also hide. What code can I use to just hide 1 workbook?
我通常打开多个工作簿,在一个工作簿上,我有一个隐藏工作簿并显示用户窗体的 VBA 代码。但是当我打开那个工作簿时,我当前打开的所有工作簿也将隐藏。我可以使用什么代码来隐藏 1 个工作簿?
Here are the codes I've tried:
以下是我尝试过的代码:
ThisWorkbook.Application.Visible = False
Windows(ThisWorkbook.name).Visible = False
Application.Windows(1).visible = false
With Windows(ThisWorkBook.name).visible = False
works with closing only one workbook, it messes with the workbook and the sheets don't show at all. I can't even close the excel workbook without using the task manager.
使用Windows(ThisWorkBook.name).visible = False
仅关闭一个工作簿的作品,它会弄乱工作簿,并且根本不显示工作表。如果不使用任务管理器,我什至无法关闭 Excel 工作簿。
回答by MikeD
ThisWorkbook.Application.Visible = False
will change the Visible
property of the applicationrunning your workbook, i.e. an instance of Excel.EXE ... if this instance is running your other books, too, then as a consequence all these books will disappear from screen.
ThisWorkbook.Application.Visible = False
将更改运行您的工作簿Visible
的应用程序的属性,即 Excel.EXE 的一个实例...如果该实例也在运行您的其他书籍,那么所有这些书籍都会从屏幕上消失。
To hide a single workbook, use
要隐藏单个工作簿,请使用
ActiveWindow.Visible = False
or alternatively, if the workbook you want to hide (e.g. "MyWorkbook") is not the active one
或者,如果您要隐藏的工作簿(例如“我的工作簿”)不是活动的
Windows("MyWorkbook").Visible = False
Pay attention that hiding a window also moves the pointer to the ActiveSheet, likewise when you reverse this (i.e. ...Visible = True
) the displayed sheet becomes active.
请注意,隐藏窗口也会将指针移动到 ActiveSheet,同样,当您反转此操作(即...Visible = True
)时,显示的工作表将变为活动状态。