vba在打开时显示userform,隐藏工作表,但保留任务栏图标(vba show userform upon opening, hide worksheet, but keep taskbar ic

编程入门 行业动态 更新时间:2024-10-22 17:31:36
vba在打开时显示userform,隐藏工作表,但保留任务栏图标(vba show userform upon opening, hide worksheet, but keep taskbar icon)

我有一个用户窗体在打开工作簿时打开。 Excel也是隐藏的,这样用户窗体就会显示给用户。

Private Sub Workbook_Open() Application.Visible = False UserForm1.Show vbModeless End Sub

但是,这也隐藏了Excel任务栏上的图标,因此当用户单击远离用户窗体时,除非使用alt +选项卡或关闭/最小化用户窗体前面的其他窗口,否则无法返回该窗体。 我不希望用户这样做,有些甚至可能会尝试再次打开表单(假定它已关闭),导致重新打开的提示和错误,我也不想这样做。

实质上,我需要在用户窗体的任务栏上有一个图标。

一旦用户窗体关闭,我就会关闭Excel

Unload UserForm1 Application.Quit

我在互联网上发现的这个问题的例子并没有完全达到我想要做的。 更改窗体以最小化并以模态方式打开以将图标保留在任务栏中,而不让用户编辑工作表

Application.WindowState = xlMinimized UserForm1.Show (1)

但是,这有两个问题.....第一 - 用户表单不成为焦点,第二 - 用户可以点击任务栏图标,表单现在可以在用户窗体后面看到,这不是我所要的能够做到。

I have a userform that opens upon the opening of the workbook. Excel is also hidden so that the userform is all that is shown to the user.

Private Sub Workbook_Open() Application.Visible = False UserForm1.Show vbModeless End Sub

However, this also hides the icon for Excel on the taskbar, so when a user clicks away from the userform they cannot get back into it unless using alt+tab or closes/minimises other windows that are in front of the userform. I do not want the users to do this and some may even try to open the form again (Presuming It is closed), causing re-open prompts and errors that I do not want either.

Essentially, I need an icon on the taskbar for the userform.

Once the userform is closed I have it so that Excel closes

Unload UserForm1 Application.Quit

Examples I have found on the internet for this problem don't quite achieve what I am trying to do. Changing the form to minimise and open as modal works to keep the icon in the taskbar and not let the user edit the worksheet

Application.WindowState = xlMinimized UserForm1.Show (1)

But this has 2 problems..... 1st - the userform doesn't become the focus, 2nd - the user can click on the taskbar icon and the sheet is now visible behind the userform, which is not what I what them to be able to do.

最满意答案

而不是隐藏应用程序最小化工作簿:

ThisWorkbook.Windows(1).WindowState = xlMinimized

The answer posted by Gareth on this question:

Excel Useform: How to hide application but have icon in the taskbar

Worked to give me a taskbar icon and was a simple copy and paste.

Thanks all for the help.

更多推荐

本文发布于:2023-08-02 04:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1368404.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:任务栏   图标   工作   vba   userform

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!