5

I'd like to have my own help file in my Excel program.

In the

Private Sub Workbook_Open()

I have

Application.OnKey "{F1}", "Help"

That works when I'm on the Excel sheet but my application is based on a fullscreen main userform which is displayed modeless.

When the userform is visible it blocks the F1 key somehow and the macro doesn't fire.

I thought that modeless forms didn't block code execution.

Any hints how can I make this work?

YowE3K
  • 23,852
  • 7
  • 26
  • 40
Sphinx
  • 628
  • 7
  • 15

1 Answers1

5

You need to trap the keyDown event on the UserForm itself. When the UserForm has got the focus, whatever Key you press it goes to the UserForm.

'/UserForm1 is a sample name.

Private Sub UserForm_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
     If KeyCode = 112 Then '/ F1
        Call Help
     End If
End Sub
cyboashu
  • 10,196
  • 2
  • 27
  • 46
  • Didn't tought about that. Thanks Unfortunatelly this doesn,t work I tried to trap `Keydown` `KeyUp` and `KeyPress`. None of them is fired when I use keyboard with the form displayed fullscreen. Looks like the form doesn't get focus. From the begening. There is a form displayed full screen. Couple of images on a form and a big frame with some controls on it. That's all. – Sphinx Jan 24 '17 at 08:44