+ Reply to Thread
Results 1 to 7 of 7

msgbox on error

  1. #1
    Ciara
    Guest

    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. #2
    papou
    Guest

    Re: msgbox on error

    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" <Ciara@discussions.microsoft.com> a écrit dans le message de news:
    2516C6D6-ABC8-4FE2-8DD7-DCA7D65FED1F@microsoft.com...
    >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. #3
    Ciara
    Guest

    Re: msgbox on error

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

    thanks,

  4. #4
    Ciara
    Guest

    Re: msgbox on error

    sorry i mean 'label' not defined

  5. #5
    Dave Peterson
    Guest

    Re: msgbox on error

    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. #6
    Ciara
    Guest

    Re: msgbox on error

    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. #7
    Dave Peterson
    Guest

    Re: msgbox on error

    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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1