Show Sitemap ..Help2HTMLHelpWinHelp

Using the VBA Excel Example File

After downloading the example file from the download area you should unzip the files to a temporary folder.

Note - Security Updates

In a connected world security updates are now a fact of life. Get used to them. Microsoft have done a mighty job of securing Windows starting with XP SP2 released in Aug 2004. Since then a string of updates have reduced the humble CHM to the status of a humble local help system. It's a shame but we need to move on.

The .zip file includes a "CHM-example.chm" file. When coming over the net and unzipped to a local drive not all of the content is shown in the help viewer.

So you have to register this CHM file - you can do this with HHReg - HTML Help Registration Utility a freeware tool by ec-software.


to open the CHM file right-click the saved file, click Properties, and then click Unblock.

Now continue ..

Context-sensitive Help for a button

Double-click "CHM_VBA_example.xls" and allow Macro's - dependent on your security properties. You can see two buttons calling the help window for following Context-ID:

Start the Visual Basic Editor and see how the code works.

Context-sensitive Help for a function

A file runs automatically when starting Excel with the file above or go to Tools | Macros (or press Alt+F8) and run "AddUDFToCategory"

In the "Insert Function" dialog box you see a category "Date & Time" - select it.

So, as you can see there are two functions "DayName" and "TestMacro" on the dialog box. Click "Help on the function" to call the help window and show the topic mapped to the function e.g. context-ID=20000.

The code from the EXCEL Macro is:

Sub AddUDFToCategory()
' insert after Description line [optional]: Category:=2, _ => Date & Time
' see also Excel help for Application.MacroOptions
Application.MacroOptions _
Macro:="TestMacro", _
Description:="This function gives back the 'Hello world' message!", _
Category:=2, _
HelpFile:=ThisWorkbook.Path & "\CHM-example.chm", _
Application.MacroOptions _
Macro:="DayName", _
Description:="A Function That Gives the Name of the Day", _
Category:=2, _
HelpFile:=ThisWorkbook.Path & "\CHM-example.chm", _
End Sub

See the example application and Excel's own Help topic on the Application.MacroOptions method for further details.

Context-sensitiv help for a message box button

Excel's Visual Basic for Application can optionally display a Help button on a message box or input box function.

The following code snippet shows an example:

' Display a message box with a help button linked to a help topic
MsgBox "The 'Hello World' message for testing this function!.", _
Buttons:=vbOKOnly + vbMsgBoxHelpButton, _
HelpFile:=ThisWorkbook.Path & "\CHM-example.chm", _


Top ...