|
-
Nov 12th, 2007, 10:42 AM
#1
Thread Starter
Addicted Member
[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?
-
Nov 12th, 2007, 03:32 PM
#2
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
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
-
Nov 12th, 2007, 04:08 PM
#3
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|