View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default How check if Application.Run fails??

Hi Robert,

Firstly I assume that you mean you are running a Sub in another workbook;
not a Function. A Function usually refers to User Defined Function (UDF for
short).

Now to check if the called Sub actually runs, insert a MsgBox with a message
immediately after the Sub name that indicates that the sub has been called.
(Can delete it after testing)

As for errors, the real test of this is "Does it do what it is supposed to
do?"
However, you can insert an On Error Goto ErrorRoutine where ErrorRoutine is
a label which is normally just before the End Sub. On the line prior to the
label you insert Exit Sub so that if it gets to the Exit Sub then it has
completed without error and exits and the only way it processes the code
after ErrorRoutine is if an error sent it to there.

Example where Test is the called sub.

Sub Test()

MsgBox "Sub Test has been called. Click OK to continue."

On Error Goto ErrorRoutine

'Your code here

Exit Sub 'If gets to here then finished so exit.

ErrorRoutine: 'Note the Colon at the end of the label.

'You might be able to insert more info in the message re the error
Msgbox "An error has been encountered"

End Sub.


Having said all that, if you are calling the sub from code in a Forms
module, sometimes if there is a compile error in the code then the sub simply
does not run or it locks up Excel. Always compile your code before running it
and there is a possiblility that some errors witll be detected. To compile
code, Select Menu item Debug - Compile. Note that compile does not
necessarily detect errors of logic in the code.


--
Regards,

OssieMac