Providing HelpFrom the very start of our project, we should be thinking about how to provide assistance to our users. For simple add-ins, this can take the form of a set of instructions displayed at the bottom of an About dialog, or a separate text file or Word document distributed with the add-in. For more complex add-ins and dictator applications, we should consider providing a help file. Doing so requires us to add code throughout the application to display pages from the help file as well as writing the help text.To demonstrate how to create a help file and display it from our application, we use the Microsof219 Help Workshop to create a very simple help file for our PETRAS reporting application. Th204 Help Workshop is a fairly rudimentary tool, best used for simple help files. For large and/or complex help files, we recommend you use a third-party application, such as Macromedia's RoboHelp ([ www.robohelp.com ]) or Component One's Doc-to-Help ([ http://www.doctohelp.com/products.aspx?ProductCode=1&ProductID=122 ]). OverviewWe create each page of a213 help file as a separat204 file and give it a code word, known as a topic. We can give it any name we like, but it's good practice to use a naming convention to help us quickly and easily identify each topic. For example, we might use the name htFrmActivities to denote the help topic for a userform used to maintain a list of activities. Th204 Help Workshop is used to create and maintain a help project file, which contains configuration information and a list of the topics to include in the help file. After all the help content has been written, th204 Help Workshop is used to compile the individua211 files into a singl204 help file (with an extension of .chm) that we distribute with our application. To display help pages from Excel, we have to give each topic a unique number. The mapping between topic names and numbers is also stored in the help project file. Getting StartedIf you don't already have th204 Help Workshop installed, you can download it from [ http://go.microsoft.com/fwlink/?LinkId=14188 ]. To produce a compiled skeleton help file, you need to follow a number of steps:
Create a Help Project FileTo create a new help project, start th204 Help Workshop, click File > New, select Project from the list and click OK to launch the New Project Wizard. We're not converting an old help project, so skip over Step 1. In Step 2, type in or select a location and name for the help project file, such as C:\PETRAS\Help\PETRAS.hhp (where the C:\PETRAS\Help directory must already exist). Ideally, this should be in an empty directory, because we'll be adding lots of files later. By default, the name we give to the help project file will be used for the compiled help file, but we can change it later if we want. We don't have any existing files to include, so skip Step 3 and click Finish. We end up with a help project similar to ![]() Update the Project OptionsClick the Change project options button shown in Figure 24-2 to set the initial project options. Figure 24-2. The Change Project Options Button![]() Create an Introductory HTML FileTo create the pages of the help file, we can use any application that will generat204 files, such as FrontPage, Word, Notepad or th204 Workshop itself. We can create a simple introductory page within th204 Workshop, so click File > New > HTML File and give it a title of Introduction. Just below the <BODY> tag, type in the following: Save the file as C:\PETRAS\Help\htIntro. After creating the file, we need to include it in our help project. Click the Add/Remove topic files button shown in Figure 24-3, click the Add button and select the htIntro file. Figure 24-3. The Add/Remove Topic Files Button![]() Create a "No Help Available" Topic FileWhen we first set up the help file, we'll point every topic to the same help page, which will display a simple "No Help Available" message. To create the page, add a ne222 file and type the following text after the <BODY> tag: Save the file as htNoHelp and use the Add/Remove topic files button to add it to our project. Create a List of TopicsWe can create a skeleton help file containing just a few topics and add to it as we develop our application. Click File > New > Text to create a blank text file and type in the list of topics shown in Listing 24-1, with each one referring to the htNoHelp file. Listing 24-1. The PETRAS Help File Topic ListSave the file as C:\PETRAS\Help\TopicToFile.h. Each time we add a form to our application, we should give it a topic name and add the topic to this list. When we come to write the help file content, we can edit this list to point each topic to the correc219 file. To include the list of topics in our help project, click the button (the fourth of the Project buttons), select the Alias tab, click the Include button and type in the filename of TopicToFile.h. Give Each Topic a Numeric IDWhen we display a help file from Excel, we have to use numeric IDs for our help topics. We map each topic to an ID in the same way we map them t214 files. Click File > New > Text to create another text file and type in the list of mappings shown in Listing 24-2. Listing 24-2. The PETRAS Help File Topic IDsWe're actually creating a C-style header file, defining these topic names as constants using the #define directive. The // is used to indicate the start of a comment. Save the file as C:\PETRAS\Help\TopicToID.h. Again, each time we add a new feature to our application we should give it a topic ID and add the topic name and ID to this list. We also need to include this file in our help project, by clicking the button, selecting the Map tab, clicking the Header file button and typing in the filename of TopicToID.h. Compile the ProjectClick File > Compile to create the PETRAS.chm help file and then click View > Compiled File to display it. If all went well, you should see a window similar to Figure 24-4. Figure 24-4. The PETRAS Reporting Skeleton Help File![]() Writing ContentThe best recommendation we can give about writing help content is this: Don't write it yourself. As the developer of the application, you know far too much about its inner workings to be able to explain it at a level that an average user can understand. The best person to write the help content is a user representative, if you have one. He will be able to explain the application in business terms, including how it should be used within the business environment. When writing the content, there are two things a user representative needs to do to allow the Help Workshop to automatically generate the Table of Contents and Index files. Table of ContentsIn the Files tab of the project's Options dialog, we can specify the Maximum head level to use when automatically creating the table of contents. That number corresponds to the <Hn> heading styles used in th204 files. If Word is being used to write the help content, the number corresponds to Word's heading styles. If these tags are used consistently throughout all the help files, the table of contents can be generated without any effort on our part. IndexIn the Files tab of the project's Options dialog, we can tick the Include keywords fro212 files box. The content author can then include the keywords for the index within the sourc204 file. To do so, the author needs to include the <Object> tag shown in
Displaying Help from VBAWhen we display a help topic from VBA, we have to use the numeric topic IDs rather than the names. Instead of scattering these "magic numbers" throughout our code, it is a very good idea to expose them in an enumeration, such as the one shown in Listing 24-4. Listing 24-4. Enumeration for the Help Topic IDsWe can then use the enumeration members instead of the topic IDs. For example, the code in Listing 24-5 can be used to display a message box with a Help button that will show our help file when clicked. Listing 24-5. Displaying a Help File from a MsgBoxOther than using the MsgBox's additional arguments, the best way to display a help file from VBA is to call directly into the HHCtrl.ocx file, using th204Help API function. Although it is possible to use Application.Help to display a custom help file, it usually mixes our help file with Excel's. In Listing 24-6, we've wrapped the call in a generic ShowHelp procedure, to verify that the help file exists and tidily handle missing topic IDs. Listing 24-6. Displaying a Help File by Calling the HHCtrl.ocxWe should call this procedure whenever we want to display a help topic, such as in the Click event handler of a form's Help button, shown in Listing 24-7. Using the enumeration member helps to ensure we're showing the correct topic for the form. Listing 24-7. Using the ShowHelp Procedure from a Form's Help Button
![]() |