If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > How does the program detect the user's control

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-08-06, 14:01
accessman2 accessman2 is offline
Registered User
 
Join Date: Sep 2005
Posts: 313
How does the program detect the user's control

Hi,

In VBA,
Can we detect whether or not the user click "Tab" key, or Arrow-keys, or mouse pointer to move/select the cell?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 09-11-06, 08:03
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
Hi accessman2

I am not sure what you mean by "Tab" key, but I have assumed it is the sheet tabs ?

To detect worksheet Tab Click (and Ctl+PageUp/Down) you can use the following events in the 'ThisWorkbook' module

Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    MsgBox "Tab Clicked (Sheet changed TO " & Sh.Name & ")"
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    MsgBox "Sheet changed  (" & Sh.Name & ")  Cell " & Target.Address
End Sub

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
    MsgBox "Tab Clicked (Sheet changed FROM " & Sh.Name & ")"
End Sub
and to detect moving around a sheet (Curser keys, Tab key, move click) you can use the following events in the individual sheet module(s). ALso sheet changes
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    MsgBox "Changed"
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    MsgBox "Moved"
End Sub
Does that help ?

MTB
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On