Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default disable EXCEL macro runtime-error

Hello,

I call EXCEL's VBA macro from VB code.
Sometimes macro might run into runtime errors, which leads users to
VBA environment.

Can I disable the runtime errors?

I searched but can not locate a similar session about this.
Thanks in advance.

Ting
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default disable EXCEL macro runtime-error

You can trap the error and have the user report it:

Sub Whatever()
Dim 'Stuff
'assign variables
On Error GoTo ErrHandler:
'your code
ErrHandler:
If Err.Number < 0 then
ErrMsg = Error(Err.Number
MsgBox "Error " & ErrMsg & "has occured. Record " _
& "this number for debugging"
Exit Sub
End If
End Sub


" wrote:

Hello,

I call EXCEL's VBA macro from VB code.
Sometimes macro might run into runtime errors, which leads users to
VBA environment.

Can I disable the runtime errors?

I searched but can not locate a similar session about this.
Thanks in advance.

Ting

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default disable EXCEL macro runtime-error

Had typos.

Sub Whatever()
Dim 'Stuff
'assign variables
On Error GoTo ErrHandler:
'your code
ErrHandler:
If Err.Number < 0 then
ErrMsg = Error(Err.Number)
MsgBox "Error " & ErrMsg & "has occured. Record " _
& "this number for debugging"
Exit Sub
End If
End Sub



"JLGWhiz" wrote:

You can trap the error and have the user report it:

Sub Whatever()
Dim 'Stuff
'assign variables
On Error GoTo ErrHandler:
'your code
ErrHandler:
If Err.Number < 0 then
ErrMsg = Error(Err.Number
MsgBox "Error " & ErrMsg & "has occured. Record " _
& "this number for debugging"
Exit Sub
End If
End Sub


" wrote:

Hello,

I call EXCEL's VBA macro from VB code.
Sometimes macro might run into runtime errors, which leads users to
VBA environment.

Can I disable the runtime errors?

I searched but can not locate a similar session about this.
Thanks in advance.

Ting

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default disable EXCEL macro runtime-error

Thanks for the answer.

But sometimes the error is inevitable because of input data.
I can manage to change the macros, but considering the backwards
compatibility issues, error sure will come up again.

No way to skip them just as I can do by using "on error resume next"
inside the macro itself?


Ting


On Nov 13, 12:15*pm, JLGWhiz
wrote:
Had typos.

Sub Whatever()
Dim 'Stuff
'assign variables
* * On Error GoTo ErrHandler:
* * 'your code
ErrHandler:
* If Err.Number < 0 then
* * ErrMsg = Error(Err.Number)
* * MsgBox "Error " & ErrMsg & "has occured. *Record " _
* * & "this number for debugging"
* * Exit Sub
* End If
End Sub

"JLGWhiz" wrote:
You can trap the error and have the user report it:


Sub Whatever()
Dim 'Stuff
'assign variables
* * On Error GoTo ErrHandler:
* * 'your code
ErrHandler:
* If Err.Number < 0 then
* * ErrMsg = Error(Err.Number
* * MsgBox "Error " & ErrMsg & "has occured. *Record " _
* * & "this number for debugging"
* * Exit Sub
* End If
End Sub


" wrote:


Hello,


I call EXCEL's VBA macro from VB code.
Sometimes macro might run into runtime errors, which leads users to
VBA environment.


Can I disable the runtime errors?


I searched but can not locate a similar session about this.
Thanks in advance.


Ting


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default disable EXCEL macro runtime-error

Personally, I would not want to disable them or skip them. If the code is
throwing errors, I would want to know what the error is and fix the code.
Errors caused by input can be fixed by anticipating the error and building
the code to accomodate the bad input, and guide the user to providing the
correct input. Most user initiated errors can be avoided by using If...Then
statements with criteria that produces a message box if the user makes the
wrong input. The message box then instructs them with the correct type of
input. If there are limited choices for the user, then you could use ListBox
to restrict them to only those choices that will not produce errors.

There are many ways around the problem of errors opening the VBE, but
ignoring the fact that the code allows that error is not something I would
recommend.




" wrote:

Thanks for the answer.

But sometimes the error is inevitable because of input data.
I can manage to change the macros, but considering the backwards
compatibility issues, error sure will come up again.

No way to skip them just as I can do by using "on error resume next"
inside the macro itself?


Ting


On Nov 13, 12:15 pm, JLGWhiz
wrote:
Had typos.

Sub Whatever()
Dim 'Stuff
'assign variables
On Error GoTo ErrHandler:
'your code
ErrHandler:
If Err.Number < 0 then
ErrMsg = Error(Err.Number)
MsgBox "Error " & ErrMsg & "has occured. Record " _
& "this number for debugging"
Exit Sub
End If
End Sub

"JLGWhiz" wrote:
You can trap the error and have the user report it:


Sub Whatever()
Dim 'Stuff
'assign variables
On Error GoTo ErrHandler:
'your code
ErrHandler:
If Err.Number < 0 then
ErrMsg = Error(Err.Number
MsgBox "Error " & ErrMsg & "has occured. Record " _
& "this number for debugging"
Exit Sub
End If
End Sub


" wrote:


Hello,


I call EXCEL's VBA macro from VB code.
Sometimes macro might run into runtime errors, which leads users to
VBA environment.


Can I disable the runtime errors?


I searched but can not locate a similar session about this.
Thanks in advance.


Ting





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
Runtime error in Macro. Tel Excel Discussion (Misc queries) 4 July 20th 09 02:21 PM
runtime error 9 in my macro [email protected] Excel Programming 2 February 14th 08 06:07 PM
Disable macro at runtime Sandy Excel Worksheet Functions 2 May 12th 07 11:56 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
naming tab macro error runtime error 1004 D Excel Programming 3 February 28th 05 01:32 AM


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

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

About Us

"It's about Microsoft Excel"