如何在excel VBA中隐藏userform excel book而不是其他excel [英] How to hide userform excel book and not other excel in excel VBA

查看:394
本文介绍了如何在excel VBA中隐藏userform excel book而不是其他excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone,



我在excel vba中有一个userform。

我想要的是在表单中隐藏excel书打开。但是过去常常关闭所有其他开放的excel书籍。



我想只关闭与其相关联的表格的特定Excel。



任何帮助或提示都会有很大的帮助。



我尝试过的事情:



Hello Everyone,

I have a userform in excel vba.
What I wanted was to hide the excel book when the form opens. But that used to close all other open excel books as well.

I would like to close only the particular excel that has the form associated with it.

Any help or hint will be of great help.

What I have tried:

Application.Visible=False



此行关闭所有其他打开excel工作簿。并且使其成为真实保持打开用户形式的优秀。



这不起作用


This line closes all other open excel workbooks. And making it true keeps open the excel for userform.

And this does not work

ThisWorkbook.ActiveSheet.Visible = False

推荐答案

planetz [ ^ ]写道:

我想只关闭具有与之关联的表单的特定Excel。

I would like to close only the particular excel that has the form associated with it.





简而言之:你不能! 只要关联工作簿是 UserForm 的父级,您无法关闭该工作簿(嵌入在其中)。



您只能通过最小化来模仿与工作簿相关的窗口隐藏。



In a short: You can't! As long as associated workbook is a parent of UserForm, you can't close that workbook (which is embedded in it).

You can only imitate the hide of window associated with workbook, by minimizing it.


实际上,您可以!如果你可以开始隐藏它。



将工作簿保存为支持宏的加载项(.xlam)

并使用工作簿打开事件来加载用户表单



如果您打算最终显示工作簿,那么这可能不可行。



Actually, you CAN! If you're OK with it starting hidden.

Save the workbook as a macro enabled add-in (.xlam)
and use the workbook open event to load up your user form

If you intend to eventually show the workbook, then this may not be workable.

Private Sub Workbook_Open()
    
    Load UFTest
    UFTest.Show
    
End Sub





您的宏代码可能需要修改以确保您引用了你想要的工作簿/工作表/范围。



这可能比它的价值更麻烦,但试一试!



或者,您可以使用PERSONAL.xlsb工作簿来存放用户表单。当你启动excel时,这通常是不可见的,但代码和表单是可用的。



我想这一切都取决于你的用户表格将做什么以及什么它可能需要与之交互的工作簿,或者您是否要分发工作簿以供其他人使用....(不建议使用PERSONAL工作簿。)



And your macro code may need to be modified to make sure that you're referencing the workbook/worksheet/range that you intend.

This may prove to be more hassle than it's worth, but give it a shot!

OR, you could use your PERSONAL.xlsb workbook to house the user form. This is generally not visible when you start excel, but the code and forms are useable.

I guess that it all depends on what your user form will be doing and what workbooks it might need to interact with, or whether you'll be distributing the workbook for others to use.... (not advisable with the PERSONAL workbook.)


这篇关于如何在excel VBA中隐藏userform excel book而不是其他excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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