Microsoft Office 2000/Visual Basic Programmer's Guide |
You can use the Assistant to display a balloon containing buttons and labels that users can click to open custom Help topics. As with other methods of displaying custom Help topics, you can use the Help method of the Application object to display a custom Help topic in Excel and PowerPoint, but you must use an API call to HTML Help to display a custom Help topic in Word and Access.
The following procedure can be used from Excel or PowerPoint (if you replace ActiveWorkbook.Path
with ActivePresentation.Path
) to display a Help balloon with labels and buttons for two topics:
Sub HelpFromAssistant()
Dim intTopic As Integer
Dim blnVisible As Boolean
Dim strMsg As String
blnVisible = Assistant.Visible
' Determine if the Assistant is already visible.
If blnVisible = False Then
With Assistant
.Visible = True
.Animation = msoAnimationIdle
End With
Else
Assistant.Animation = msoAnimationIdle
End If
' Display Help balloon with two buttons and store user's
' selection in intTopic.
With Assistant.NewBalloon
.BalloonType = msoBalloonTypeButtons
.Heading = "Displaying Help Topics"
.Text = "Select a topic:"
.Labels(1).Text = "Topic One"
.Labels(2).Text = "Topic Two"
.Button = msoButtonSetCancel
.Mode = msoModeModal
intTopic = .Show
End With
' Determine which button the user clicked and display the Help
' topic. This code works only in Excel 2000 because it refers to
' a .chm file. Replace with a WinHelp 4.0 .hlp file if you also
' need this code to run in Excel 97.
Select Case intTopic
Case 1
Application.Help ActiveWorkbook.Path & "\sample.chm", 2001
Case 2
Application.Help ActiveWorkbook.Path & "\sample.chm", 2002
End Select
End Sub
The HelpFromAssistant procedure is available in the modHTMLHelp module in ExcelHelp.xls in the ODETools\V9\Samples\OPG\Samples\CH13 subfolder on the Office 2000 Developer CD-ROM.
The same code can be used from Word or Access if you replace the calls to the Help method of the Application object with calls to the HtmlHelp API to display the topics. For Word, the Select Case statements would look like this:
Select Case intTopic
Case 1
Call HtmlHelp(0, ActiveDocument.Path & "\sample.chm", HH_HELP_CONTEXT, _
ByVal 2001&)
Case 2
Call HtmlHelp(0, ActiveDocument.Path & "\sample.chm", HH_HELP_CONTEXT, _
ByVal 2002&)
End Select
In Access, you would use the Path property of the CurrentProject object to display a topic from a compiled HTML Help file located in the same folder as the current database. For example:
Call HtmlHelp(0, CurrentProject.Path & "\sample.chm", HH_HELP_CONTEXT, ByVal 2001&)
For more information about working with the Office Assistant, see Chapter 6, "Working with Shared Office Components."
If you are creating an Access run-time application and installing it on a computer that does not have Office installed, the Assistant object is not available. However, the Office Assistant is based on the Microsoft Agent ActiveX control, which is freely distributable. For Access run-time applications, you can use the Agent control to provide the full range of Assistant services without accessing the Assistant's object model. For more information about using the Agent control, see the Microsoft Agent Web site at http://www.microsoft.com/intdev/agent.
If Office is not installed on the computer where your Access run-time application will be used, you may also need to install HTML Help components. For more information, see "Redistributing HTML Help Components" earlier in this chapter.