Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    Darmstadt, Hessen, Germany
    Posts
    128
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Last Question In 2005 (xp-pro - office 2003)

    hi, dear experts...

    here is my last question for 2005...i promise...

    how can i disable the use of "ctrl" and the "break"-key so that a user can't interrupt my macro?!

    thank you...

    best,
    wolfgang

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Last Question In 2005 (xp-pro - office 2003)

    Hi,
    You can use Application.EnableCancelKey for this - see the Excel help for full details and note the warning about disabling it altogether!
    HTH.

    e.g.:
    <pre>Sub testloop()
    On Error GoTo err_handle
    Application.EnableCancelKey = xlErrorHandler
    For n = 1 To 100000
    DoEvents
    Next n
    Exit Sub

    err_handle:
    If Err.Number = 18 Then
    MsgBox "Don't press that again!"
    End If
    End Sub
    </pre>

    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    Darmstadt, Hessen, Germany
    Posts
    128
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Re: Last Question In 2005 (xp-pro - office 2003)

    hi rory...

    thank you very much for your advise...

    do i read you correctly that there simply is now way to disable those keys in order to stop a user from interrupting a code?!

    what if i have a workbook open macro which contains a password to be answered and all there is to it is to press those magic keys?

    i realize of course, that a user only only needs to disable macros at loading time of the workbook...

    best,
    wolfgang

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Last Question In 2005 (xp-pro - office 2003)

    You can set Application.EnableCancelKey to xlDisabled - you just need to be aware that if your code gets stuck (for example in an infinite loop), you will have to terminate Excel manually (e.g. via Task Manager).
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    Darmstadt, Hessen, Germany
    Posts
    128
    Thanks
    15
    Thanked 2 Times in 2 Posts

    Re: Last Question In 2005 (xp-pro - office 2003)

    hi rory..

    that's it - many "thank yous" and i wish you a peaceful and healthy 2006...

    best,
    wolfgang

Posting Permissions

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