Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Disabling Ctrl, ALT keys

I have an application that disables the CTRL and ALT key when a workbook
is open. The purpose is to prevent users from activitating a shortcut
key or hot key. I want to make sure that when I close the workbook
that the CTRL and ALT key work normally when I open a different
workbook or spreadsheet.
Would appreciate any help with this.

Thanks in advance.


Tommy


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Disabling Ctrl, ALT keys

I assume that you talking about Excel.
How are the keys disabled? The normal way would be to use "OnKey", but CRTL
and ALT can only be specified in combination with other keys.

Let's assume that you have disabled the CTRL + TAB combination using

Sub TestDisableOnKey()
Application.OnKey "^{TAB}", ""
End Sub

You can enable it using

Sub TestEnableOnKey()
Application.OnKey "^{TAB}"
End Sub

More specifically, to ensure it is re-enabled when you close the workbook
add this procedure to "ThisWorkbook"

Private Sub Workbook_BeforeClose(Cancel As Boolean)
TestEnableOnKey
End Sub

You also need to consider what happens when a user moves to and from that
workbook to another. These procedures (again placed in "ThisWorkboo") will
only allow the keys to be disabled when your main workbook is active.

Private Sub Workbook_Activate()
TestDisableOnKey
End Sub

Private Sub Workbook_Deactivate()
TestEnableOnKey
End Sub

--

Regards
Andy Wiggins
www.BygSoftware.com
Home of "Save and BackUp",
"The Excel Auditor" and "Byg Tools for VBA"


"turk5555" wrote in message
...
I have an application that disables the CTRL and ALT key when a workbook
is open. The purpose is to prevent users from activitating a shortcut
key or hot key. I want to make sure that when I close the workbook
that the CTRL and ALT key work normally when I open a different
workbook or spreadsheet.
Would appreciate any help with this.

Thanks in advance.


Tommy


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Disabling Ctrl, ALT keys

This is the code that I added in ThisWorkbook:

Private Sub Workbook_Open()
Application.OnKey "%{F11}", ""
Application.OnKey "%{F8}", ""
End Sub

Private Sub App_WorkbookBeforeClose(ByVal Wb As Workbook, _
Cancel As Boolean)

TestEnableOnKey

End Sub

This code disables the shortcut key ALT+F8 which displays the MACROS
list box and the shortcut key ALT+F11 which displays the Visual Basic
Editor. (NOTE: Your original code for enabling the shortcut keys upon
closing the workbook was not correct. I found the above version that
works)

When I open the workbook (workbook 1) that contains the above code this
works fine. If I open another workbook (workbook 2), and try to use
the above shortcut keys these shortcut keys remain disabled.

If I close the workbook 1, these shortcut keys remain disabled and I
can't use them in workbook 2. In order to enable these shortcut keys
it is necessary to close workbook 2 and closedown (exit) Excel, then
open workbook 1 and closedown Excel again.
When I open workbook 2 the shortcut keys are enabled.

Weird, but at least I understand what happens.

Thanks for all your help.



Tommy


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Disabling Ctrl, ALT keys

See inline comments

--

Regards
Andy Wiggins
www.BygSoftware.com
Home of "Save and BackUp",
"The Excel Auditor" and "Byg Tools for VBA"


"turk5555" wrote in message
...

This code disables the shortcut key ALT+F8 which displays the MACROS
list box and the shortcut key ALT+F11 which displays the Visual Basic
Editor. (NOTE: Your original code for enabling the shortcut keys upon
closing the workbook was not correct. I found the above version that
works)


The code was tested in Excel XP before posting - it works in XP - which
version are you using?

When I open the workbook (workbook 1) that contains the above code this
works fine. If I open another workbook (workbook 2), and try to use
the above shortcut keys these shortcut keys remain disabled.

If I close the workbook 1, these shortcut keys remain disabled and I
can't use them in workbook 2. In order to enable these shortcut keys
it is necessary to close workbook 2 and closedown (exit) Excel, then
open workbook 1 and closedown Excel again.
When I open workbook 2 the shortcut keys are enabled.


Here are the notes from my first answer together with the Activate and
DeActivate procedures. Did you use them?

.... You also need to consider what happens when a user moves to and from
that
workbook to another. These procedures (again placed in "ThisWorkboo") will
only allow the keys to be disabled when your main workbook is active.

Private Sub Workbook_Activate()
TestDisableOnKey
End Sub

Private Sub Workbook_Deactivate()
TestEnableOnKey
End Sub


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
Disabling certain keys on keyboard leerem Excel Discussion (Misc queries) 2 August 21st 09 03:37 PM
Excel 2007: Ctrl+PgUp or Ctrl+PgDn with Protected Sheets DrDave Excel Discussion (Misc queries) 1 July 28th 08 04:12 AM
Use of Ctrl/end keys - Excel 2002 samoan Excel Discussion (Misc queries) 1 January 14th 08 09:45 PM
cut & paste with short cut keys (ctrl C V) with absolute cell refe Modeller Dave Excel Discussion (Misc queries) 1 December 7th 04 11:14 PM
Disabling Shortcut Hot Keys Dan Gesshel Excel Programming 1 September 15th 03 09:12 PM


All times are GMT +1. The time now is 11:47 AM.

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

About Us

"It's about Microsoft Excel"