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)

Download the latest version of HelpSmith!
Error Accessing and Displaying CHM Files: Reasons and Solutions
Graphics in Help Files
Technical Documentation Know-how and Services
HelpSmith 3 is Released
Better UX through Better UA
How to connect HTML Help (.CHM) files to your Microsoft Office VBA application (for MS Word, MS Excel, MS Access developers)
Help Authoring on Steroids
HelpSmith 3.4 Enables Integration of Help Systems with YouTube and Google Analytics

Add to Reddit Add to Digg Add to del.icio.us 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


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

  1.  Bill | October 6, 2007 @ 9:30 pm

    With Vista you should also register the location of the chm file in the registry.

    As well, the above solution will not work with the vbMsgBoxHelpButton feature with meessage boxes. Any ideas on how to fix this?

Leave a Reply