PC Review


Reply
Thread Tools Rate Thread

disable EXCEL macro runtime-error

 
 
tingxing@gmail.com
Guest
Posts: n/a
 
      13th Nov 2008
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 With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      13th Nov 2008
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


"(E-Mail Removed)" 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 With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      13th Nov 2008
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
>
>
> "(E-Mail Removed)" 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 With Quote
 
tingxing@gmail.com
Guest
Posts: n/a
 
      13th Nov 2008
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 <JLGW...@discussions.microsoft.com>
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

>
> > "tingx...@gmail.com" 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 With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      14th Nov 2008
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.




"(E-Mail Removed)" 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 <JLGW...@discussions.microsoft.com>
> 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

> >
> > > "tingx...@gmail.com" 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable macro at runtime Sandy Microsoft Excel Worksheet Functions 2 12th May 2007 11:56 AM
Excel 2003 Macro Error - Runtime error 1004 =?Utf-8?B?Q293?= Microsoft Excel Misc 2 7th Jun 2005 01:40 PM
Re: Disable CLR runtime error dialog box Sunny Microsoft Dot NET 0 24th Jun 2004 04:40 PM
Run Excel Macro from Access Runtime Error Pete Microsoft Access VBA Modules 1 10th Jun 2004 01:51 PM
excel macro runtime error 1004 charles osborne Microsoft Excel Misc 8 2nd May 2004 09:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:56 AM.