Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default How check if Application.Run fails??

Hello! I am using Application.Run to run macros in another
workbook that is currently open. How can I check or test
if the Application.Run function call fails or returns an error
code?? Would it also be wise to use the "On Error Resume Next"
before calling the Application.Run function??


thank you!


  #2   Report Post  
Posted to microsoft.public.excel.programming
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default How check if Application.Run fails??

I would turn the macros into function and add error handling to return True
or False depending on success, something like

Public Function TestRun() As Boolean

On Error GoTo TestRun_Error

TestRun = True

'some code that if it errors calls the errorhandler

'such as

Debug.Print 1 / 0

Exit Function

TestRun_Error:
TestRun = False
End Function


and thn call it like so

If Not Application.Run("Personal 2003.xls!TestRun") Then

MsgBox "oops!"
End If


HTH

Bob

"Robert Crandal" wrote in message
...
Hello! I am using Application.Run to run macros in another
workbook that is currently open. How can I check or test
if the Application.Run function call fails or returns an error
code?? Would it also be wise to use the "On Error Resume Next"
before calling the Application.Run function??


thank you!




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CreateObject("Word.Application") fails though Word session starts [email protected] Excel Programming 16 May 6th 08 02:40 PM
Application.Calculation = xlCalculationManual fails AM Excel Programming 1 June 9th 06 12:23 AM
check if in list else quit application Pierre via OfficeKB.com[_2_] Excel Programming 3 November 7th 05 07:28 PM
check value with array, Application.Match Przemek Excel Programming 5 August 25th 05 12:09 PM
Existance Check Fails ChuckM[_2_] Excel Programming 7 January 31st 04 03:02 AM


All times are GMT +1. The time now is 12:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"