How do I associate a help file with my program and then call it from a menu?



Read and add posts to the Visual Basic 6.0 Forums

Download some of my programs and OCXs

Read the Tips here

The old style forum is still available here




From: Harry
Date: Thu 02/06/2005 5:25 AM
Subject: Inserting Help File
Question: Hello Sir,
I have created a help file called "wpad.hlp" for my application. How to call that help file when I click Help from Help menu.

Answer by Martin Allen:

The first thing to do is to set the HelpFile property of the App object.  When doing this, you will need to make sure that if the program is located in the root of the drive, that there will not be too many '\' characters in the string:

Dim s As String

s = App.Path

If Len(s) = 3 Then
    App.HelpFile = s & Replace("wpad.hlp", "\\", "\")
    App.HelpFile = s & Replace("\wpad.hlp", "\\", "\")
End If

Now, when the F1 key is pressed, the help file will be displayed.  The code for your Help menu should be:

Private Sub mnuHelpContents_Click()
SendKeys "{F1}"
End Sub

This presses the F1 key virtually, which in turn displays the help file.  There should be no shortcut key for the menu item, which displays the help file as F1 is used to open the help file anyway.

Martin Allen 1999 - 2011.  Last updated Thursday 11 August 2011 08:36:04 PM +0100.