
Private Const fmShiftMask As Integer = 1 'SHIFT was pressed. 'NOTE: See the MoveFocus routine's header commentary for specifics about how the tab-sequence is managed in 'Declare the module-global tab-order control constants and variables If you need to do any special processing of, for example, text-box contents, see the dummy-comment that denotes that purpose in the MoveFocus subroutine. YourControlName" statement so that it references the name of your newly managed control!
IMPORTANT: In the new KeyDown event handler, edit the " Set ThisCntrl = Me. Copy the code from one of the exiting KeyDown event handlers. Add a KeyDown event handler for the newly managed control. Add its name to the list in its desire tab-order position. To change the Tab order of managed controls, all you have to do is edit the TabOrderDef list! If you need to add a new control to be managed: If that behavior is desired, it can be easily added. In this version, if you use the Enter key on a command-button, it will just execute the button’s Click event but will not move to the next control. On the worksheet, select one of the controls and then use the Tab and/or Enter keys to experiment with moving from control to control. Open the VBE editor and copy the code below into the Sheet1 module.
Retain their default names, which will be “CommandButton1”, “TextBox1”, and “CommandButton2”, respectively.
On Sheet1, add three ActiveX controls: a command-button, a text-box, and a second command-button. It may look rather complicated at first but its use is actually very straightforward. So here’s a fairly complete solution for managing ActiveX controls’ Tab order using VBA code. If your application requires the user to interact with both the containing worksheet’s cells and the ActiveX controls, you can’t easily define a fully-functional transparent Frame control through which the user can see cell values, let alone interact with them behind the frame. You must start over and replicate your application inside the Frame, as described in Use tab/return to go from one ActiveX box to the next?.
If you first create a complex set of ActiveX controls on a worksheet and then, belatedly, decide that you need to manage their Tab order, you can’t just cut and paste the existing, sheet-level controls into a newly added Frame control.But there are two unfortunate problems with frames: The simplest solution is to initially put the controls in a Frame control and let it manage the Tab order.