Results 1 to 3 of 3

Thread: [RESOLVED] VBA UserForm Keyboard Shortcuts

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Posts
    223

    Resolved [RESOLVED] VBA UserForm Keyboard Shortcuts

    I really like the keyboard shortcuts to resize and move controls on an Excel spreadsheet. I love being able to nudge a control over using control-arrow key.

    I can't seem to find anything equivalent for the UserForm interface for VBA.

    Is there? If not, is there a way of defining one?

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VBA UserForm Keyboard Shortcuts

    this appears to work
    vb Code:
    1. Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    2. If KeyCode = 37 Then TextBox1.Left = TextBox1.Left - 10
    3. If KeyCode = 39 Then TextBox1.Left = TextBox1.Left + 10
    4. End Sub
    you could use a generic sub with select case for the arrowkeys, passing the control like
    vb Code:
    1. Private Sub TextBox1_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
    2. moveme Val(keycode)
    3. End Sub
    4.  
    5. Sub moveme(keycode As Integer)
    6. If keycode = 37 Then Me.ActiveControl.Left = Me.ActiveControl.Left - 10
    7. If keycode = 39 Then Me.ActiveControl.Left = Me.ActiveControl.Left + 10
    8. End Sub
    for each control you want to be able to move you would need to put moveme in the keydown, you could also resize based on the shift value, but you would need to pass that too
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Posts
    223

    Re: VBA UserForm Keyboard Shortcuts

    Oh, my. I believe you've just opened up a floodgate of experimentation for me.

    Thanks!!! :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width