From: David on
Just toying with some ideas...

1) Any way to recover the application after the above command and then
crashing?

2) Anyone got error handling code to show the application and also preserve
the 'original' error message and ability to go to the offending line of code
with 'Debug'?
From: Jacob Skaria on
Hi David

1.
Application.Visible = False
'some code here
Application.Visible = True

2. Refer the below link on using ERL function

http://www.fmsinc.com/free/NewTips/VBA/errorhandling/linenumber.html


--
Jacob (MVP - Excel)


"David" wrote:

> Just toying with some ideas...
>
> 1) Any way to recover the application after the above command and then
> crashing?
>
> 2) Anyone got error handling code to show the application and also preserve
> the 'original' error message and ability to go to the offending line of code
> with 'Debug'?
From: Dave Peterson on
If this is happening when you're testing, then you could use a VBS script to
unhide the hidden excel application.

I wouldn't expect any user to go through all this, though. I'd only use it
while testing the code.

========
dim myXL
On Error Resume Next
Set myXL = GetObject(, "Excel.Application")
If Err.Number = 429 Then
msgbox "Excel is not running"
else
myxl.visible = true
end If
On Error GoTo 0
Set myxl = nothing
=======

Copy the stuff between the "========" lines and paste into NotePad. Then save
it as a nicely named .vbs file (UnhideXL.vbs ???).

The bad news is that if you have several hidden instances of excel, you'll have
to close the visible instance, unhide, close, unhide, ...

You can pop up the task manager (ctrl-shift-Escape is one way), look at the
processes tab to determine how many excel.exe's are running (visible or hidden).

Again, I wouldn't make this part of the user experience. But it's good while
developing.

The .VBS file that I use includes other office programs:

======
dim myXL
On Error Resume Next
Set myXL = GetObject(, "Excel.Application")
If Err.Number = 429 Then
msgbox "Excel is not running"
else
myxl.visible = true
end If
On Error GoTo 0
Set myxl = nothing

dim myWord
On Error Resume Next
Set myWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
msgbox "Word is not running"
else
myWord.visible = true
end If
On Error GoTo 0
Set myWord = nothing

dim myOutlook
On Error Resume Next
Set myOutlook = GetObject(, "outlook.Application")
If Err.Number = 429 Then
msgbox "Outlook is not running"
else
myOutlook.visible = true
end If
On Error GoTo 0
Set myOutlook = nothing

dim myPPT
On Error Resume Next
Set myPPT = GetObject(, "Powerpoint.Application")
If Err.Number = 429 Then
msgbox "Power Point is not running"
else
myPPT.visible = true
end If
On Error GoTo 0
Set myPPT = nothing

dim myAcc
On Error Resume Next
Set myPPT = GetObject(, "Access.Application")
If Err.Number = 429 Then
msgbox "Access is not running"
else
myAcc.visible = true
end If
On Error GoTo 0
Set myAcc = nothing
===========

(just in case you need it.)

David wrote:
>
> Just toying with some ideas...
>
> 1) Any way to recover the application after the above command and then
> crashing?
>
> 2) Anyone got error handling code to show the application and also preserve
> the 'original' error message and ability to go to the offending line of code
> with 'Debug'?

--

Dave Peterson