View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Shevlin Ryan Shevlin Ryan is offline
external usenet poster
 
Posts: 6
Default How to leave a combo box?

Thanks, Tom. This is very similar to what Bob Phillips posted, but
different enough to spark some questions. I'll see what I can dig up
for answers. If I can't find any, I'll be back.

Tom Ogilvy wrote:

http://groups.google.com/groups?thre...GP11.phx .gbl

Here is some code posted by Rob Bovey that might give you some ideas:

Message 2 in thread
From: Rob Bovey )
Subject: Navigating via tabbing on a worksheet



Newsgroups: microsoft.public.excel.programming
Date: 2003-06-06 14:40:38 PST


The TabOrder property is an inherited property. That means it comes from
the container that a control is situated in. A UserForm supplies this
property, a worksheet doesn't. You can still tab amongst controls on a
worksheet, you just have to code it yourself using each control's KeyDown
event procedure.

In the sample event procedure below I'll assume a hypothetical situation
where we have three textboxes: TextBoxPrevious, TextBoxCurrent, and
TextBoxNext. This event procedure shows you how to use VBA to emulate
tabbing behavior. Pressing Tab moves from TextBoxCurrent to TextBoxNext and
pressing Shift+Tab moves from TextBoxCurrent to TextBoxPrevious. The Up and
Down arrow keys and the Enter key are given similar behavior.

Private Sub TextBoxCurrent_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
Dim bBackwards As Boolean
Select Case KeyCode
''' These are the only keys we care about.
Case vbKeyTab, vbKeyReturn, vbKeyDown, vbKeyUp
Application.ScreenUpdating = False
''' Determine if we need to move backwards.
bBackwards = CBool(Shift And 1) Or (KeyCode = vbKeyUp)
''' In Excel 97 we must select a cell before activating another
control.
Sheet1.Range("A1").Select
''' Activate the appropriate control based on key(s) pressed.
If bBackwards Then TextBoxPrevious.Activate Else _
TextBoxNext.Activate
Application.ScreenUpdating = True
End Select
End Sub