Unhide Excel Application Session
Asked Answered
L

5

8

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.

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.

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.

This isn't a massive deal but I'm just interested if anyone knows how to resurrect such a session.

Luminescence answered 24/4, 2012 at 8:23 Comment(4)
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?Kale
@SiddharthRout I completely agree (you should see the state of the rest of the code!). I'm just having to run the app to produce some reports and am getting fed up with having to kill sessions when I forget to keep the VBE open. Unfortunately, I don't have the control to make the changes required. 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.Luminescence
Hi creamyegg. If you open any excel file it will make the current excel instance visible.Uxorial
@Uxorial That's a great alternative. Never noticed that behaviour before. ThanxLuminescence
K
15

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.

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.

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

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

Kale answered 24/4, 2012 at 9:2 Comment(1)
Thank you @SiddharthRout, I'll give that I go. What I mean by I'm not able to make the changes, is that in my place, the bureaucracy to make a simple, one line code change is horrendous and so I just don't want to even go there. It's not worth the pain! :)Luminescence
K
1

A good solution!

Open up Word, assuming you have it, and open the VBA Editor there, then open the Immediate Window (Ctrl+G) and type:

Getobject(, "Excel.Application").Visible = true

and press enter.

Korn answered 29/7, 2017 at 3:50 Comment(0)
I
0

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.

If you can find it, put Application.Visible = True just before it and voila.

Iceberg answered 4/1, 2013 at 8:36 Comment(0)
L
0

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
Luca answered 6/6, 2013 at 10:44 Comment(0)
E
0

No need for word macro at all.

Open up another excel workbook.

Hit Ctrl+F11 to go to the VBA editor and there yoy will see the running but hidden excel file on the left. Search the code of the hidden application file for Application.Visible = False and comment it out. Save and restart the file. Alternatively you can get back the application to show without closing if you type Application.Visible = True in the immediate window (Ctrl+G)

Expunction answered 16/12, 2021 at 7:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.