vba 取消隐藏 Excel 应用程序会话
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10294268/
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
Unhide Excel Application Session
提问by markblandford
I have an Excel VBA method (I didn't write it) that runs and one of the first things it does is hide the Excel session Application.Visible = False
.
我有一个运行的 Excel VBA 方法(我没有编写它),它做的第一件事就是隐藏 Excel session Application.Visible = False
。
However, when the method has finished, it does not unhide the Excel session so it remains open and listed in the Task Manager but is hidden and seemingly unusable.
但是,当该方法完成时,它不会取消隐藏 Excel 会话,因此它保持打开状态并列在任务管理器中,但被隐藏并且似乎无法使用。
Does anyone know, without have the VBE open (so one can access the Immediate Window and run Application.Visible = True
), how to unhide this Excel session? At the moment, I'm simply having to kill the session using the Task Manager.
有谁知道,如果没有打开 VBE(这样就可以访问立即窗口并运行Application.Visible = True
),如何取消隐藏此 Excel 会话?目前,我只需要使用任务管理器终止会话即可。
This isn't a massive deal but I'm just interested if anyone knows how to resurrect such a session.
这不是什么大问题,但我只是对是否有人知道如何恢复这样的会议感兴趣。
回答by Siddharth Rout
Like I said, it's not a big deal but was just interested if anyone knew of shortcut key or anything to bring it back.
就像我说的,这没什么大不了的,但只是对是否有人知道快捷键或任何可以将其带回来的东西感兴趣。
There is no shortcut as such that I am aware of but you can do this.
没有我知道的捷径,但你可以做到这一点。
Open MS Word and paste this code in the VBA Editor. Close all open instances of Excel which are visible and then run and this code. This will make a hidden instance visible. Manually close the instance and repeat the process if there are more instances.
打开 MS Word 并将此代码粘贴到 VBA 编辑器中。关闭所有可见的打开的 Excel 实例,然后运行此代码。这将使隐藏的实例可见。如果有更多实例,请手动关闭实例并重复该过程。
Option Explicit
Sub Sample()
Dim oXLApp As Object
'~~> Get an existing instance of an EXCEL application object
On Error Resume Next
Set oXLApp = GetObject(, "Excel.Application")
On Error GoTo 0
oXLApp.Visible = True
Set oXLApp = Nothing
End Sub
I am not deliberately using a loop as the hidden instance can have a workbook which you might like to save?
我不是故意使用循环,因为隐藏实例可以有一个您可能想保存的工作簿?
If you want you can convert the above code to a VB Script document which you can directly run from the desktop.
如果需要,您可以将上述代码转换为可以直接从桌面运行的 VB 脚本文档。
Unfortunately, I don't have the control to make the changes required.
不幸的是,我无法控制进行所需的更改。
What do you exactly mean? Is the VBA Password Protected? If no then my suggestion is still the same as earlier
你到底是什么意思?VBA 密码是否受保护?如果没有那么我的建议还是和之前一样
This is a case of poor programming. Even if we give a code to close all hidden Excel instances, that won't help you. Because next time you run that macro, you will face the same problem again. Why not edit the existing code and add Application.Visible = True at the end? Is the VBA password protected? – Siddharth Rout 28 mins ago
这是一个糟糕的编程案例。即使我们提供了关闭所有隐藏 Excel 实例的代码,也无济于事。因为下次运行该宏时,您将再次面临同样的问题。为什么不编辑现有代码并在最后添加 Application.Visible = True ?VBA 密码是否受保护?– Siddharth Rout 28 分钟前
回答by John David Barbosa
Open up Word, assuming you have it, and open the VBA Editor there, then open the Immediate Window (Ctrl+G) and type:
打开 Word,假设你有它,然后在那里打开 VBA 编辑器,然后打开立即窗口 (Ctrl+G) 并键入:
Getobject(, "Excel.Application").Visible = true
Getobject(, "Excel.Application").Visible = true
and press enter.
并按回车键。
回答by Vasil
I had a similar problem and solved it with code line reordering.
我有一个类似的问题,并通过代码行重新排序解决了它。
Look for a line like this ActiveWorkbook.Close
that might be the reason you cannot unhide the session.
寻找这样的一行,这ActiveWorkbook.Close
可能是您无法取消隐藏会话的原因。
If you can find it, put Application.Visible = True
just before it and voila.
如果你能找到它,就放在Application.Visible = True
它之前,瞧。
回答by Nemet Attila
as code:
作为代码:
sub runthis()
dim xl as object
set xl = new excel.application 'create session
xl.workbooks.open filename:= "?yourpath?" 'open wb in the new session
xl.visible=true 'this is what you need, show it up!
'rest of the code
end sub