#1   Report Post  
Ciara
 
Posts: n/a
Default msgbox on error

i have protected a worksheet - if i click a command button I get

Run - time error '1004
Application defined or object defined error
(with options to debug etc....)

which is good because i don't want the command buttons to work while the
sheet is protected

however, i want my own message to come up with no options to debug/end/help.

any ideas on code for this?
  #2   Report Post  
papou
 
Posts: n/a
Default

Hello Ciara

On Error GoTo Err_Hdler
'your code here
Exit Sub

Err_Hdler:
Select Case Err.Number
Case Is = 1004
MsgBox "This is your message"
Case Else
Msgbox "Other message"
End Select

HTH
Cordially
Pascal

"Ciara" a écrit dans le message de news:
...
i have protected a worksheet - if i click a command button I get

Run - time error '1004
Application defined or object defined error
(with options to debug etc....)

which is good because i don't want the command buttons to work while the
sheet is protected

however, i want my own message to come up with no options to
debug/end/help.

any ideas on code for this?



  #3   Report Post  
Ciara
 
Posts: n/a
Default

it says 'error not defined' what am i leaving out?

thanks,
  #4   Report Post  
Ciara
 
Posts: n/a
Default

sorry i mean 'label' not defined
  #5   Report Post  
Dave Peterson
 
Posts: n/a
Default

It might just be easier to check the protection status of the worksheet first:

Option Explicit
Sub testme()

Dim wks As Worksheet

Set wks = ActiveSheet

With wks
If .ProtectContents _
Or .ProtectDrawingObjects _
Or .ProtectScenarios Then
MsgBox "Can't run on a protected sheet"
Exit Sub
End If
End With

End Sub

Ciara wrote:

i have protected a worksheet - if i click a command button I get

Run - time error '1004
Application defined or object defined error
(with options to debug etc....)

which is good because i don't want the command buttons to work while the
sheet is protected

however, i want my own message to come up with no options to debug/end/help.

any ideas on code for this?


--

Dave Peterson


  #6   Report Post  
Ciara
 
Posts: n/a
Default

Thanks Dave - that works - but once the msg box comes up and I click 'ok' i
still get the error message - can i put in a line of code that will cancel
the error message?

"Dave Peterson" wrote:

It might just be easier to check the protection status of the worksheet first:

Option Explicit
Sub testme()

Dim wks As Worksheet

Set wks = ActiveSheet

With wks
If .ProtectContents _
Or .ProtectDrawingObjects _
Or .ProtectScenarios Then
MsgBox "Can't run on a protected sheet"
Exit Sub
End If
End With

End Sub

Ciara wrote:

i have protected a worksheet - if i click a command button I get

Run - time error '1004
Application defined or object defined error
(with options to debug etc....)

which is good because i don't want the command buttons to work while the
sheet is protected

however, i want my own message to come up with no options to debug/end/help.

any ideas on code for this?


--

Dave Peterson

  #7   Report Post  
Dave Peterson
 
Posts: n/a
Default

I would have bet that "exit sub" would stop the procedure.

I'm betting that your code does something else, though. You may want to post
that portion of it.

Ciara wrote:

Thanks Dave - that works - but once the msg box comes up and I click 'ok' i
still get the error message - can i put in a line of code that will cancel
the error message?

"Dave Peterson" wrote:

It might just be easier to check the protection status of the worksheet first:

Option Explicit
Sub testme()

Dim wks As Worksheet

Set wks = ActiveSheet

With wks
If .ProtectContents _
Or .ProtectDrawingObjects _
Or .ProtectScenarios Then
MsgBox "Can't run on a protected sheet"
Exit Sub
End If
End With

End Sub

Ciara wrote:

i have protected a worksheet - if i click a command button I get

Run - time error '1004
Application defined or object defined error
(with options to debug etc....)

which is good because i don't want the command buttons to work while the
sheet is protected

however, i want my own message to come up with no options to debug/end/help.

any ideas on code for this?


--

Dave Peterson


--

Dave Peterson
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
Error trapped only while stepping through the code - Not triggered when run Jeff Excel Discussion (Misc queries) 7 March 7th 05 06:29 PM
Error trapped only while stepping through the code - Not triggered when run Jeff Excel Discussion (Misc queries) 0 February 28th 05 06:26 PM
Problem with VBA returning the contents of a long formula. [email protected] Excel Discussion (Misc queries) 2 February 23rd 05 12:14 AM
ERROR Pinto1uk Excel Discussion (Misc queries) 1 February 8th 05 03:15 AM
Error when entering and exiting excel Randy Excel Discussion (Misc queries) 1 January 11th 05 03:17 PM


All times are GMT +1. The time now is 03:55 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"