How to Connect HTML Help with your Visual Basic/VBA Application
If you are a Visual Basic/VBA (MS Word, MS Excel, MS Access, etc) developer, you can integrate an HTML Help (.CHM) system with your application by using HTML Help API calls. This article illustrates how to do this.
In the Visual Basic environment, click "Project|Add Module" to insert a new module for the required declarations. In VBA, use the menu command "Insert|Module".
Write the code as shown below to declare the HTML Help function and constants which are needed to perform operations such as calling a help topic, displaying help Index, and so on.
Public Const HH_DISPLAY_TOPIC = &H0 Public Const HH_DISPLAY_TOC = &H1 Public Const HH_DISPLAY_INDEX = &H2 Public Const HH_HELP_CONTEXT = &HF Declare Function HTMLHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" (ByVal hwndCaller As Long, ByVal pszFile As String, ByVal uCommand As Long, ByVal dwData As Long) As Long
To display a help topic from your HTML Help CHM file, simply call the HTMLHelp() function with the HH_HELP_CONTEXT
constant as shown below.
HTMLHelp 0, MyHelpFile, HH_HELP_CONTEXT, MyTopicContextID
where MyHelpFile
stands for the full path to your .CHM file, and MyTopicContextID
is the numeric topic ID as defined in your help project.
Similarly, you can implement the Show Help command, when the user calls the help system from a menu or by pressing F1 in your application. In this case, we do not call a help topic, but pass the HH_DISPLAY_TOC
constant to the HTMLHelp() function.
HTMLHelp 0, MyHelpFile, HH_DISPLAY_TOC, 0
You can download the unit HTMLHelpAPI.bas from our web site.
To import this unit into your Visual Basic/VBA project:
-
For Visual Basic: On the "Project" menu, click "Add Module";
For VBA: On the "File" menu, click "Import File". - Find and select the file "HTMLHelpAPI.bas".
- Then click "Open".
Once the module is successfully imported, the HTMLHelp() function will be available for usage from any module of your VB/VBA application.
You can download a sample MS Access application by clicking this link.