VBA Move UserForm Without a Mouse: Keyboard Methods

VBA & macros · Updated November 3, 2026

VBA Move UserForm Without a Mouse: Keyboard Methods

Yes. In Excel VBA, move a UserForm in code by changing its Left and Top properties; to move it while it is open without touching the mouse, handle arrow keys in a focused control and adjust those properties. The form’s position is measured in points, so a small change moves it a manageable distance on screen.

What “move a UserForm” can mean

There are two common situations. You may want the form to open at a chosen position, or you may want a user to reposition it after it appears. Both use the same properties: Left controls horizontal position and Top controls vertical position. Increasing Left moves the form right; increasing Top moves it down.

These properties describe the form’s position, not the position of a control inside it. To move a button within the form, change that button’s Left or Top instead. A UserForm also has Width and Height, which change its size rather than its location.

For a one-time adjustment, set the properties before showing the form. For interactive movement, put the position changes in code that runs while the form is displayed, such as a control’s keyboard event. That distinction matters: a macro that tries to run from a worksheet while a modal form is open will normally wait until the form closes.

Set the opening position in VBA

A UserForm’s StartUpPosition property determines how Excel initially places it. Set it to 0 (Manual) when you want your own Left and Top values to take effect. You can set this property in the form’s Properties window in the VBA editor, or in its initialization code.

To use the code example below, add a TextBox to the form, name it txtMoveKeys, and leave it enabled and available for keyboard focus. Set its TabStop property to True. The initialization procedure places the form 100 points from the coordinate origin; change those sample values to suit your layout.

Private Sub UserForm_Initialize()
    ' Use the Left and Top values below rather than automatic centering.
    Me.StartUpPosition = 0
    Me.Left = 100
    Me.Top = 100
End Sub

The values are points, not pixels. A point is 1/72 of an inch; the number of screen pixels represented by a point depends on display scaling. Consequently, a value such as 100 is a positioning value, not a promise that the form will appear exactly 100 pixels from an edge.

Move the open form with arrow keys

A UserForm does not need a mouse event to move. A keyboard event on a control that has focus can change the form’s position. This example uses the TextBox as a dedicated keyboard target: the arrow keys move the form by 10 points, and Shift plus an arrow moves it by 50 points. The code belongs in the UserForm’s code module, not in a standard module.

Private Sub UserForm_Activate()
    ' Start with the keyboard target focused.
    Me.txtMoveKeys.SetFocus
End Sub

Private Sub txtMoveKeys_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
                                ByVal Shift As Integer)
    Dim stepSize As Single

    ' Make Shift plus an arrow a larger movement.
    stepSize = 10
    If (Shift And fmShiftMask) <> 0 Then stepSize = 50

    Select Case KeyCode
        Case vbKeyLeft
            Me.Left = Me.Left - stepSize
        Case vbKeyRight
            Me.Left = Me.Left + stepSize
        Case vbKeyUp
            Me.Top = Me.Top - stepSize
        Case vbKeyDown
            Me.Top = Me.Top + stepSize
        Case Else
            Exit Sub
    End Select

    ' Stop the arrow key from moving the TextBox caret as well.
    KeyCode = 0
End Sub

Private Sub txtMoveKeys_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    ' Keep this dedicated movement TextBox from collecting typed characters.
    KeyAscii = 0
End Sub

When the form activates, focus goes to the TextBox, so the user can press an arrow immediately. The KeyDown event receives the key before its normal action; setting KeyCode to zero prevents that arrow from also moving a caret. The KeyPress handler suppresses ordinary typed characters in this dedicated control. If users need to type into a different TextBox, they can tab to it; tabbing away also means the movement TextBox no longer receives arrow keys until focus returns.

To use a different distance, change stepSize. A value such as 5 gives finer adjustments; a larger value moves the form faster. The Shift modifier is optional, and you can remove that test if one consistent step size is preferable. The procedure handles only the four arrow keys, so other keys continue through their normal handling.

Keyboard-only alternatives

A dedicated TextBox is convenient, but it is not the only way to avoid mouse input. Choose a method that fits how people will use the form:

  • Arrow-key target: Use a focused control’s KeyDown event as above. This is suitable for repeated, precise repositioning.
  • Move buttons: Add buttons such as “Left,” “Right,” “Up,” and “Down,” and give them keyboard access keys using their Accelerator property. Their click procedures can change Me.Left or Me.Top. This makes the available actions visible and avoids taking over arrow keys in an entry field.
  • Opening-position settings: Set StartUpPosition to a built-in centering option when users do not need to reposition the form after it opens. This solves placement at startup, not movement during use.

Excel’s Application.OnKey can assign keys to macros while Excel is handling normal worksheet input, but it is not usually the best first choice for a form. Focus and modal-dialog behavior complicate which code receives a key. An event attached to a control on the form makes the relationship between focus and movement explicit. Windows API calls are another advanced option, but they add platform and declaration concerns that are unnecessary for ordinary VBA forms.

Keep movement predictable and usable

Moving a form without a mouse is useful for keyboard accessibility, for adjusting a dialog that covers important worksheet cells, and for interfaces where a mouse is unavailable. It is also worth giving users a way to tell that movement keys are available. A short label such as “Use the arrow keys to move this window” can help; a visible move button is an alternative if the TextBox approach is not obvious.

Consider how far the form can travel. The basic sample does not impose screen boundaries, so repeated key presses can move it partly or entirely off-screen. You can limit movement by checking the proposed position before assigning it, but an exact boundary calculation depends on the available display area and how the form is positioned. A simple practical safeguard is to use modest step sizes and provide a reset button that restores known Left and Top values.

Also consider focus. A keyboard handler on one TextBox will not receive keys while a command button or another field has focus. That is expected behavior, not evidence that Left and Top stopped working. Users can return to the movement target with Tab or Shift+Tab, depending on the form’s tab order. If arrow keys are needed for selecting text or navigating other controls, use dedicated buttons with access keys instead of capturing arrows.

Modal forms, modeless forms, and timing

A form shown with the default modal behavior keeps the user in the dialog until it is hidden or unloaded. Its own event procedures still run, so the arrow-key approach works with a modal form. However, a separate worksheet macro generally cannot be started and used to move that same modal form while it blocks interaction with Excel.

A modeless form, shown with vbModeless, allows interaction with Excel while the form remains open. That can be useful for a form that accompanies worksheet work, but it makes focus management more important: the form may not have focus when the user presses a key. For reliable keyboard movement, make sure the user can return focus to the form and its movement control. The movement code itself does not require a modeless form.

Common problems and practical checks

  • The form opens centered despite position values: Check that StartUpPosition is set to Manual (0) before display. A centering setting can override the intended startup placement.
  • Arrow keys do nothing: Confirm that the movement TextBox is enabled, visible, and focused, and that the event procedure is in the correct UserForm module. The control name in the procedure must match its actual name.
  • The caret moves instead of the form: Verify that the event sets KeyCode = 0 for handled arrow keys. If you use a different event or control, check its event signature and key handling.
  • The form moves in unexpectedly large increments: Remember that the properties use points. Reduce the step value and test at the display scaling used by the intended users.
  • The form disappears off-screen: Restore a known starting position, reduce the step size, or add bounds checks. Avoid assuming that Excel’s window dimensions are the same as the entire desktop, especially with multiple displays.

Before running a macro that changes a workbook or its interface, save a copy of the workbook. VBA macros cannot be undone with Ctrl+Z. Although the sample changes only the open form’s position, the same caution is useful when adding or adapting event code.

Frequently Asked Questions

Can I move a VBA UserForm with the keyboard alone?
Yes. Give a control focus and handle its KeyDown event. Change Me.Left or Me.Top for the relevant arrow key, then set the handled KeyCode to zero if you want to suppress the key’s usual action.

What units do UserForm Left and Top use?
They use points, not pixels. One point is 1/72 of an inch. Display scaling affects how many pixels correspond to a point, so test the movement step on the screens where the form will be used.

Can I move a UserForm while it is open using a worksheet macro?
It depends on how it was shown. A modal form blocks normal interaction with Excel until the form closes, so its own event code is the straightforward option. A modeless form permits Excel interaction, but focus and the reference to the displayed form must be handled appropriately.

Why do the arrow keys stop moving the form?
The control with the movement event probably no longer has focus, or the form is not active. Return focus to the movement control with the tab order, or use buttons with keyboard access keys so movement does not depend on capturing arrows.

Can I prevent the form from moving off-screen?
Yes, by checking proposed Left and Top values against chosen limits before applying them. The simple example does not include those checks; display arrangements and scaling make a universal desktop boundary assumption unreliable.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.