vba 仅打开用户窗体而不闪烁 Excel 窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26568264/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 04:59:50  来源:igfitidea点击:

Opening Userform only without flashing Excel Window

excelvbauserform

提问by AndroidDev

I know the method as Application.Visible = Falseand Application.Screenupdating = False

我知道方法Application.Visible = FalseApplication.Screenupdating = False

When opening the file, I want the user to see onlythe userform.

打开文件时,我希望用户看到用户表单。

The thing is: with these two commands above, Excel appears for 1 second. Is it possible to do it without Excel blinking like this?

问题是:使用上面的这两个命令,Excel 会出现 1 秒钟。有没有可能在没有 Excel 像这样闪烁的情况下做到这一点?

Thanks in advance.

提前致谢。

回答by ZAT

You may try to open the excel file not with excel itself to avoid the splash. Try script to open excel file, then form will open without splash :

您可以尝试不使用 excel 本身打开 excel 文件以避免飞溅。尝试脚本打开 excel 文件,然后表单将打开而不会飞溅:

'save this in a text file, change extension as .vbs

将其保存在文本文件中,将扩展名更改为.vbs

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = false
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\USER\Desktop\yourfile.xlsm") 

'this will open excel as invisible, so to close excel you have to insert some button inside userformor something like ThisWorkbook.Close savechanges = Falseor Application.Quit

“这将打开Excel作为无形的,所以要关闭Excel你要插入一些按钮内部用户窗体或喜欢的东西ThisWorkbook.Close savechanges = FalseApplication.Quit

'and of course assuming that your form is in the workbook_open in your project like

'当然假设您的表单在您的项目中的 workbook_open 中,例如

Private Sub Workbook_Open()
'ActiveWindow.WindowState = xlMinimized
'Application.Visible = False
Application.ScreenUpdating = False
Application.EnableEvents = False
'Application.EnableAnimations = False
UserForm1.Show
End Sub