
'also because it provides the Shift/Ctrl/Alt key status. 'NOTE: Uses the KeyDown (or KeyUp) event because it is triggered for action keys like Enter and Tab, and Private Sub CommandButton2_KeyDown(ByVal Ke圜ode As MSForms.ReturnInteger, ByVal Shift As Integer)
#Keycode for check box word windows
If Ke圜ode = AtlTabKe圜ode Then Exit Sub 'Sometimes used by programmers to swap windows when debuggingĬall DoActionKey(Ke圜ode, ThisCntrl, TabIdx, Shift) Static TabIdx As Integer 'Static so its value is persistent, but is local to this event handler Set ThisCntrl = Me.CommandButton1 'IMPORTANT: Customize to refer to this event handler's parent control! 'because it provides the Shift/Ctrl/Alt key status. 'NOTE: Uses the KeyDown (or KeyUp) event because it is triggered for action keys like Enter and Tab, and also Private Sub CommandButton1_KeyDown(ByVal Ke圜ode As MSForms.ReturnInteger, ByVal Shift As Integer) Private Const TxtBoxType As String = "TextBox" Private Const OptBtnType As String = "OptionButton" Private Const CmdBtnType As String = "CommandButton" Private Const ChkBoxType As String = "CheckBox" Private TabOrderCntrls() As OLEObject ' " Private TabOrderNames As Variant 'Is module-global so that all controls on this sheet can access it 'NOTE: See the MoveFocus routine's header commentary regarding (re)initialization of the following "CommandButton2" 'Is module-global so that all controls on this sheet can access it 'To change the Tab order of managed controls, just edit the following list: Private Const AtlTabKe圜ode As Integer = 18 'Sometimes used by programmers to swap windows when debugging Private Const fmAltMask As Integer = 4 'ALT was pressed. Private Const fmCtrlMask As Integer = 2 'CTRL was pressed. 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.
#Keycode for check box word code
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.
