Associating a Help File with Your Application


You can associate a particular HTML Help file with your Excel application in one of two ways: by using the Project Properties dialog box or by writing VBA code.

In the Visual Basic Editor (VBE), choose Tools image from book xxx Properties (where xxx corresponds to your project's name ). In the Project Properties dialog box, click the General tab and specify a compiled HTML Help file for the project. This file should have a .chm extension.

The statement that follows demonstrates how to associate a Help file with your application by using a VBA statement. The following instruction sets up an association to image from book  myfuncs.chm , which is assumed to be in the same directory as the workbook:

 ThisWorkbook.VBProject.HelpFile = ThisWorkbook.Path & "\myfuncs.chm" 

When a Help file is associated with your application, you can call up a particular Help topic in the following situations:

  • When the user presses F1 while a custom worksheet function is selected in the Insert Function dialog box.

  • When the user presses F1 while a UserForm is displayed. The Help topic associated with the control that has the focus is displayed.

Associating a help topic with a VBA function

If you create custom worksheet functions with VBA, you might want to associate a Help file and context ID with each function. After these items are assigned to a function, the Help topic can be displayed from the Insert Function dialog box by pressing F1.

To specify a context ID for a custom worksheet function, follow these steps:

  1. Create the function as usual.

  2. Make sure that your project has an associated Help file (refer to the preceding section).

  3. In the VBE, press F2 to activate the Object Browser.

  4. Select your project from the Project/Library drop-down list.

  5. In the Classes window, select the module that contains your function.

  6. In the Members Of window, select the function.

  7. Right-click the function and then select Properties from the shortcut menu. This displays the Member Options dialog box, shown in Figure 24-11.

    image from book
    Figure 24-11: Specify a context ID for a custom function in the Member Options dialog box.

  8. Enter the context ID of the Help topic for the function. You can also enter a description of the function.

Note  

The Member Options dialog box does not let you specify the Help file. It always uses the Help file associated with the project.

You might prefer to write VBA code that sets up the context ID and Help file for your custom functions. You can do this by using the MacroOptions method.

The following procedure uses the MacroOptions method to specify a description, Help file, and context ID for two custom functions ( AddTwo and Squared ). You need to execute this macro only one time.

 Sub SetOptions() '   Set options for the AddTwo function     Application.MacroOptions Macro:="AddTwo", _         Description:="Returns the sum of two numbers", _         HelpFile:=ThisWorkbook.Path & "\myfuncs.chm", _         HelpContextID:=1000 '   Set options for the Squared function     Application.MacroOptions Macro:="Squared", _         Description:="Returns the square of an argument", _         HelpFile:=ThisWorkbook.Path & "\myfuncs.chm", _         HelpContextID:=2000 End Sub 

After executing these procedures, the user can get help directly from the Insert Function dialog box by pressing F1 or by clicking the Help on This Function hyperlink.

CD-ROM  

A workbook that demonstrates this technique is available on the companion CD-ROM. The filename is function help\myfuncs.xlsm .




Excel 2007 Power Programming with VBA
Excel 2007 Power Programming with VBA (Mr. Spreadsheets Bookshelf)
ISBN: 0470044012
EAN: 2147483647
Year: 2007
Pages: 319

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net