Visual Basic for Applications

How to Integrate a CHM File with MS Office VBA Application

If you develop an MS Office application on VBA and want to integrate a CHM help file to it, you can do so by using the appropriate functions of HTML Help API.

Using the sample VBA code from this article, you can provide basic functionality such as calling a specific help topic or just showing your help file to the end-user.

Declare the HTMLHelp() API Function

First, you should add the following code that adds the HTMLHelp() function and also declares some constants that we will use.

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

Show a Specific Help Topic Using Its Context Number

The code below will open your CHM file and also display the requested topic with Context Number equal to 50:

HTMLHelp 0, "YourHelpFile.chm", HH_HELP_CONTEXT, 50

Open the Help File at Default Topic

You may also need to just open the help file, so the user will see the Table of Contents on the left side and the default topic in the right side of the HTML Help viewer.

HTMLHelp, 0, "YourHelpFile.chm", HH_DISPLAY_TOC, 0

Related Links

You can also visit the links below for information on using a CHM file in other development tools.

Download a Help Authoring Tool

You can download one of the recommendable help authoring tools that combines a rich feature-set, slight learning curve, and affordable price.

HelpSmith Download

HelpSmith main window

Product Details:

Detail Value
Product HelpSmith 7.3
Filename HelpSmithSetup.exe
File size 40 MB
Platform Windows 10/8/7/Vista/XP
System requirements 1 GHz processor, 512MB RAM, 150MB free disk space