[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?
Re: VBA UserForm Keyboard Shortcuts
this appears to work
vb Code:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 37 Then TextBox1.Left = TextBox1.Left - 10
If KeyCode = 39 Then TextBox1.Left = TextBox1.Left + 10
End Sub
you could use a generic sub with select case for the arrowkeys, passing the control like
vb Code:
Private Sub TextBox1_KeyDown(ByVal keycode As MSForms.ReturnInteger, ByVal Shift As Integer)
moveme Val(keycode)
End Sub
Sub moveme(keycode As Integer)
If keycode = 37 Then Me.ActiveControl.Left = Me.ActiveControl.Left - 10
If keycode = 39 Then Me.ActiveControl.Left = Me.ActiveControl.Left + 10
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
Re: VBA UserForm Keyboard Shortcuts
Oh, my. I believe you've just opened up a floodgate of experimentation for me.
Thanks!!! :-)