Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to disable a few keyboard keys 2

Status
Not open for further replies.

Trident1

Technical User
May 24, 2005
13
0
0
GB
I need to add something into an autostart macro that will disable the use of pageup, down and the arrow keys. I have looked through a lot on here but it mainly deals with access. I have established the keycode constants, ie. vbKeyUp is 0x26, vbKeyDown is 0x28 etc.

Will someone be kind enough to set an example of code for just one of these keys and I can hopefully workout the rest.

Many thanks.
 
but it mainly deals with access
Any chance you could say us what is the meaning of the A in your VBA issue ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hello,

Try this to disable keys:
Code:
Sub DisableKeys()
    Application.OnKey "{PGDN}", ""
    Application.OnKey "{PGUP}", ""
    Application.OnKey "{UP}", ""
    Application.OnKey "{DOWN}", ""
    Application.OnKey "{LEFT}", ""
    Application.OnKey "{RIGHT}", ""
End Sub

To reenable:
Code:
Sub EnableKeys()
    Application.OnKey "{PGDN}"
    Application.OnKey "{PGUP}"
    Application.OnKey "{UP}"
    Application.OnKey "{DOWN}"
    Application.OnKey "{LEFT}"
    Application.OnKey "{RIGHT}"
End Sub

HTH,

Eric
 
Thank you so very much.

It looks so easy when it's written down for you!

You're a saviour!!
 
Hi Trident1,

Out of interest, could you tell me why you want to disable these keys? What is it that you are presenting to your users that either has theoretically scrollable content which you wish to stop them seeing by normal use of the keyboard, or in which you want to limit their options in moving the cursor? Are you also disabling the mouse?

You probably have good reason, but I suspect that there may be a better way of achieving what you want.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Hi Tony

Principally, I simply want to keep the users in the set working area. They will be working with their own data so that doesn't pose a problem, but many of them are, how shall we say, are very novice when it comes to even using computers. If they start moving around to see what's there, they'll probably lose the screens that I've prepared for their input and set macros to move from one area to another. Regarding the mouse, Yes I will wan't to disable the scroll facility of the mouse.....any ideas?

regards
Trident
 
Hi Trident,

why not just hide the parts of the spreadsheet not in the working area? So, hide columns and rows as required, and have a macro in the Worksheet_SelectionChange event macro, check that the users haven't somehow selected a cell in a hidden area ( if they have, select a cell in the working area ).



Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 
Hi Trident,

I don't know how to restrict the mouse. I'll have a look to see what can be done but I'm not optimistic. Also, there many ways to move around a document or workbook - what application is it that you are using?

Secondly, can you not either design single screen interfaces that have nothing to scroll and/or provide a toolbar which they can always use to return?

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
I am not clear on what exactly the issue is.
[quoye] If they start moving around to see what's there, they'll probably lose the screens that I've prepared for their input [/quote]
"screens that I've prepared for their input" sounds like a userForm. If it is Modal yuo can keep the user on the "screen". If that is indeed what is going on.

What exactly do you mean by "lose the screens"?

Surely there is a way to lock the parts you need to lock. I mean, even if you had to, you could use an identification routine to determine who opened the file, and allow certain actions, and disallow others. I do that with some Word documents, locking parts (or all) depending on who opened the file.

However, again, I am unclear what the issue is precisely. I also agree with Tony about design single screen interfaces.

Gerry
sorry...my art web site is down
 
Would it help if you used the worksheet's ScrollArea property to limit the user's cell access?

Worksheets(1).ScrollArea = "D3:H10
 
Thank you all for your advice.

The worksheet scroll area restriction is brilliant for the tast in hand! The advice on locking up the keys will most certainly be useful in the future. I started to incorporate this method but then changed it in favour of the former.

To clarify my tasks for fumei, When I refer to "screens" in my request, I simply mean groups of cells that I have prepared as full screen working areas in an excel worksheet. Unfortunately, as I pointed out, some of the people that will use it may navigate outside of these areas, get lost and then close the worksheet having saved changes.

Anyway, I am a very happy bunny now. Thank you all once again....

Trident

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top