Unspecified error when pressing F1 key

KentBurel

Board Regular
Joined
Mar 27, 2020
Messages
68
Office Version
  1. 2019
Platform
  1. Windows
I have a userform that contains a text box that provides information for the first page in my workbook. I want this displayed when the workbook is first opened but only the first time. If the user wants to see the instructions again then he/she can press the F1 key. This all works until the F1 key is pressed and then I get this error message:
1588444642415.png


Here are my macros that set this up:

The Constants sheet is the first sheet in the workbook. The Constants sheet contains this code:
VBA Code:
Option Explicit

Private Sub Worksheet_Deactivate()
    Application.OnKey "{F1}"
    DisplayConstantsHelp.Hide
End Sub
Private Sub Worksheet_Activate()
    Application.OnKey "{F1}", "DisplayConstantsHelp.Show"
End Sub

The ThisWorkBook module contains this code:
VBA Code:
Sub Workbook_open()
    DisplayConstantsHelp.Show
End Sub

DisplayConstantsHelp is the name of the userform. I used this technique before to map the F1 key to a userform only when a particular sheet is displayed. Now it's giving me a strange error.

Thanks for your help.
 

Attachments

  • 1588444727580.png
    1588444727580.png
    18.8 KB · Views: 6

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I assume that the userform name is DisplayConstantsHelp

Place code in Sheet Constants code window:

Rich (BB code):
Private Sub Worksheet_Deactivate()
    Application.OnKey "{F1}"
End Sub

Private Sub Worksheet_Activate()
    Application.OnKey "{F1}", "Sheet1.DisplayForm"  ' GREEN = sheet codename,  RED = name of macro
End Sub

Private Sub DisplayForm()
    DisplayConstantsHelp.Show  'BLUE = name of userform
End Sub

F1.jpg
 
Upvote 0

Forum statistics

Threads
1,214,397
Messages
6,119,273
Members
448,883
Latest member
fyfe54

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top