VBA modeless form stops Function Keys

449 Views Asked by At

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?

1

There are 1 best solutions below

1
cyboashu On BEST ANSWER

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