代码只隐藏一个工作簿,而不是隐藏所有当前打开的工作簿 [英] Code to hide only one workbook instead of hiding all currently open workbooks

查看:315
本文介绍了代码只隐藏一个工作簿,而不是隐藏所有当前打开的工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常有多个工作簿打开,在一个工作簿上,我有一个隐藏工作簿的VBA代码,并显示一个UserForm。但是,当我打开这本工作簿时,我所有的工作簿当前被打开也将隐藏起来。我可以使用哪些代码隐藏1个工作簿?



以下是我尝试过的代码:

  ThisWorkbook.Application.Visible = False 

Windows(ThisWorkbook.name).Visible = False

Application.Windows(1).visible = false

使用 Windows(ThisWorkBook.name).visible = False 只关闭一个工作簿,它与工作簿混乱,工作表完全不显示。我不能关闭excel工作簿,而不使用任务管理器。

解决方案

ThisWorkbook.Application。 Visible = False 将更改运行工作簿的应用程序 Visible 属性,即Excel.EXE的一个实例。如果这个实例还在运行其他书籍,那么所有这些书籍都将从屏幕上消失。



要隐藏单个工作簿,请使用

  ActiveWindow.Visible = False 

或者如果要隐藏的工作簿(例如MyWorkbook)不是活动的

  Windows(MyWorkbook)Visible = False 

注意,隐藏窗口也会将指针移动到ActiveSheet,同样当你反转这个(即 ... Visible = True )时,显示的表单变为活动。


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?

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.

解决方案

ThisWorkbook.Application.Visible = False will change the Visible property of the application running 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.

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.

这篇关于代码只隐藏一个工作簿,而不是隐藏所有当前打开的工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆