How to connect HTML Help (.CHM) files to your Microsoft Office VBA application (for MS Word, MS Excel, MS Access developers)

Download the latest version of HelpSmith! »

Developers frequently ask me how they can connect HTML Help (.CHM) files to their VBA (Visual Basic for Applications) programs. A simple way to achive that is to use HTML Help API calls directly.

First, I would suggest you to create a separate module (for your convenience) where you should write the following code:

Public Const HH_DISPLAY_TOPIC = &H0
Public Const HH_DISPLAY_TOC = &H1
Public Const HH_DISPLAY_INDEX = &H2
Public Const HH_DISPLAY_SEARCH = &H3
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

Now you can display any topic from your .CHM file. To do so, simply call the HTMLHelp() function. It may look like:

HTMLHelp(0, MyHelpFile, HH_HELP_CONTEXT, MyTopicContextID)

Please note that MyHelpFile contains the file path to your .CHM file, and MyTopicContextID is the numeric topic ID as defined in your help project. The MyTopicContextID variable must be of the Long type.

As you may have noticed, there are additional constants declared in the above block of code. If you wish to show, say, the Table of Contents, just pass the HH_DISPLAY_TOC constant to the HTML Help() function. Similarly, you can display the Help Index and Search tabs.

For example:

HTMLHelp(0, MyHelpFile, HH_DISPLAY_TOC, 0)

Add to Reddit Add to Digg Add to Add to StumbleUpon Add to Facebook Add to BlinkList Add to Furl Add to Spurl Add to Fark Add to Google Add to YahooMyWeb Add to Twitter