Microsoft Office 2000/Visual Basic Programmer's Guide   

Working with Balloon Objects

The Assistant's Balloon object enables the Assistant to communicate with and get feedback from your users. Balloon objects are designed to let you create a simple interface for user interaction. They are not designed to replace complex dialog boxes.

Balloon objects can contain text that can be plain, underlined, or displayed in different colors. In addition, Balloon objects can contain labels or check boxes, certain icons, and bitmaps. Only one Balloon object can be visible at a time, but you can create multiple Balloon objects in code and use them when needed. For an example of how to create multiple Balloon objects, see the CreateMultipleBalloons procedure in the modAssistantCode module in AssistantSamples.dot in the ODETools\V9\Samples\OPG\Samples\CH06 subfolder on the Office 2000 Developer CD-ROM. For an example of how to display multiple preformatted messages stored in a database, see the ShowBalloonTour procedure in the modAssistantCode module.

You create a Balloon object by using the Assistant's NewBalloon property. Once you have created the new Balloon object, you can set its properties and then display it by using the Balloon object's Show method. The following two simple procedures illustrate many of the features of Balloon objects discussed so far. The TestCreateSimpleBalloon procedure creates two formatted strings used to specify the balloon Heading and Text properties. The procedure then creates the balSimple Balloon object by calling the CreateSimpleBalloon procedure and passing in the heading and text strings. CreateSimpleBalloon sets several other "default" properties for this balloon and then returns the new Balloon object to the calling procedure where it is displayed by using the Show method.

Sub TestCreateSimpleBalloon()
   Dim balSimple          As Balloon
   Dim strMessage         As String
   Dim strHeading         As String
   Dim blnAssistVisible   As Boolean
   
   strHeading = "This is a simple balloon."
   strMessage = "When you have finished reading this message, click OK to proceed." _
      & vbCrLf & "{cf 249}This text is red." & vbCrLf & "{cf 252}This text is blue." _
      & vbCrLf & "{cf 0}This text has a {ul 1}word{ul 0} that is underlined." _
      & vbCrLf & "This text is plain."
   blnAssistVisible = Application.Assistant.Visible
   
   Set balSimple = CreateSimpleBalloon(strMessage, strHeading)
   
   If Not blnAssistVisible Then
      Call ShowAssistant
   End If
   With balSimple
      .Show
   End With
   Application.Assistant.Visible = blnAssistVisible
End Sub

Function CreateSimpleBalloon(strText As String, _
                             strHeading As String) As Office.Balloon

   Dim balBalloon As Balloon
   
   With Application.Assistant
      Set balBalloon = .NewBalloon
      With balBalloon
         .BalloonType = msoBalloonTypeButtons
         .Button = msoButtonSetOK
         .Heading = strHeading
         .Icon = msoIconTip
         .Mode = msoModeModal
         .Text = strText
      End With
      Set CreateSimpleBalloon = balBalloon
   End With
End Function

The TestCreateSimpleBalloon and CreateSimpleBalloon procedures are available in the modAssistantCode module in AssistantSamples.dot in the ODETools\V9\Samples\OPG\Samples\CH06 subfolder on the Office 2000 Developer CD-ROM.

Note that the strMessage variable contains a string that includes embedded brackets such as {cf 252}, {cf 0}, {ul 1}, and {ul 0}. You use the {cf value} brackets to specify the color of the text that follows the bracket. You use the {ul value} brackets to specify where text underlining begins and ends. For more information about specifying text color and underlining text in Balloon objects, search the Microsoft Office Visual Basic Reference Help index for "Text property."

If you run the sample code, you will notice that the code stops executing while the Balloon object is displayed. This is because the balloon's Mode property specifies that the balloon is modal. You can also display modeless Balloon objects. For more information about modeless balloons, see "Modeless Balloons and the Callback Property" later in this chapter.