OFF98: How to Display a Custom Office Assistant Balloon

ID: Q184502

The information in this article applies to:

SUMMARY

You can use the Office Assistant to display a custom message (balloon) with the options you specify. The Assistant can display a simple message with buttons or check boxes. You can display several kinds of buttons (OK, Cancel, Retry, and so on) at the bottom of the Assistant.

This article provides sample macros that customize the Assistant.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft Support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/default.asp

Creating the Visual Basic Module

Before you create a custom message, you must first create a module. To do this, follow these steps:

1. Save and close any open workbooks, and then create a new workbook.

2. Start the Visual Basic Editor (press OPTION+F11).

3. On the Insert menu, click Module.

Simple Balloon Macro

To create a sample balloon, follow these steps:

1. Type the following code in the module:

      Sub Simple_Balloon()

          ' Create the balloon object.
          Set myballoon= Assistant.NewBalloon

          With myballoon

              .Heading = "My Balloon"
              .Text = "Click OK to close the balloon"
              .Show
          End With

      End Sub

2. Run the Simple_Balloon macro.

   The Office Assistant displays a balloon with the heading "My Balloon" in
   bold letters and a message that prompts you to click OK.

3. Click OK.

   The balloon disappears.

Balloon with a Numbered List

1. Type the following code in the module:

      Sub List_Balloon()

          ' Create the balloon object.
          Set myballoon= Assistant.NewBalloon

          With myballoon

              .Heading = "List Balloon"
              .Text = "Click OK to close the balloon."

              ' Text for the list items:
              .Labels(1).Text = "Click Save on the File menu to save " _
                  & "the file."
              .Labels(2).Text = "Click Print on the File menu to " _
                  & "print the file."

              ' Create a numbered list.
              .BalloonType = msoBalloonTypeNumbers

              ' Display the balloon.
              .Show
          End With

      End Sub

   The Office Assistant displays a balloon with a number list.

2. Click OK to close the balloon.

Balloon with Check Boxes

1. Type the following code in the module:

      Sub Balloon_Checkboxes()

          ' Create balloon object.
          Set myballoon = Assistant.NewBalloon

          With myballoon
              .Heading = "Regional Sales Data"
              .Text = "Select your region"

              ' Place OK and Cancel buttons at bottom of the balloon.
              .Button = msoButtonSetOkCancel

              For i = 1 To 3
                  .CheckBoxes(i).Text = "Region " & i
              Next

              ' Display the balloon and assign it to x.
              x = .Show

              i = 0
              Select Case x

                  Case -1 'You clicked OK.

                      ' Loop through check boxes on the balloon.
                      For Each y In .CheckBoxes
                          i = i + 1

                          If y.Checked Then
                              MsgBox "region " & i
                          End If
                      Next

                  Case -2 ' You clicked Cancel.

                      MsgBox "You clicked Cancel."
              End Select
          End With
      End Sub

2. Run the Balloon_Checkboxes macro.

   A balloon with three check boxes appears.

3. Click one or more check boxes, and then click OK.

   Messages boxes that display your choices appear.

If you click Cancel, a message box with a message that indicates you clicked Cancel appears.

Multiple Balloons

1. Type the following code in the module:

      Sub Balloon_Array()

          Dim myBalloonArray(2) As Balloon

          With Assistant
              For i = 1 To 2
                  ' Create a new balloon object.
                  Set myBalloonArray(i) = .NewBalloon
              Next
          End With

          With myBalloonArray(1)
              .Heading = "This is balloon #1."
              .Text = "Click OK to close the balloon."

              ' Display the first balloon.
              .Show
          End With

          With myBalloonArray(2)
              .Heading = "This is balloon #2."
              .Text = "Click OK to close the balloon."

              ' Display the second balloon.
              .Show
          End With

      End Sub

2. Run the Balloon_Array macro.

   The first balloon appears.

3. Click OK in the balloon.

   The second balloon appears.

4. Click OK in the balloon.

   The second balloon is dismissed.

Performing Actions Based on a Selection

1. Type the following code in the module:

      Sub Balloon_Options()

          ' Create a new balloon object.
          Set balloon1 = Assistant.NewBalloon

          With balloon1
              .Heading = "Options Balloon"

              ' Create buttons for the list items.
              .BalloonType = msoBalloonTypeButtons

              .Text = "Click an option or click OK to close the balloon."

              ' Set the text for list items.
              .Labels(1).Text = "Save your file."
              .Labels(2).Text = "Print your file."

              ' Mode must be msoModeModeless in order to use Callback
              ' property.
              .Mode = msoModeModeless

              ' Call the "ProcessOption" macro when a balloon list item is
              ' clicked.
              .Callback = "ProcessOption"

              .Show
          End With

      End Sub

      ' Every procedure specified in the Callback property is
      ' passed three arguments: the balloon that activated the
      ' procedure, the return value of the button the user pressed,
      ' and an integer that uniquely identifies the balloon that
      ' called the procedure.

      Sub ProcessOption(bln As Balloon, ibtn As Long, iPriv As Long)

          ' bln: the name of the balloon that activated the procedure
          ' ibtn: the number of the button clicked in the balloon
          ' iPriv: an integer that uniquely identifies the balloon

          Assistant.Animation = msoAnimationGoodbye

          Select Case ibtn
              Case 1
                  ' Insert your routine here.
                  bln.Close
                  bln.Text = "You chose the Save option."
                  bln.Show
              Case 2
                  ' Insert your routine here.
                  bln.Close
                  bln.Text = "You chose the Print option."
                  bln.Show

              Case Else ' You clicked something other than a list item.
                  bln.Close

          End Select

      End Sub

2. Run the Balloon_Options macro.

   A balloon with two options appears.

3. Click "Save your file."

   The balloon reappears, and the text in the balloon is "You chose the
   Save option."

4. Click "Print your file."

   The balloon reappears, and the text in the balloon is "You chose the
   Print option."

5. Click OK to dismiss the balloon.

Note: If you edit a cell within this workbook and then run this macro, choosing one of the balloon options will cause an Invalid Page Fault. The code itself runs fine as long as you do not attempt to edit any cell in the workbook prior to running macro.

REFERENCES

For more information about creating custom Office Assistant balloons, click the Office Assistant while in the Visual Basic Editor, type "balloon" click Search, and then click to view "Creating and modifying balloons."

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Microsoft Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q179216
   TITLE     : OFF98: How to Use the Microsoft Office Installer Program

Additional query words: XL98 OFF98
Keywords          : kbprg kbtool kbdta kbdtacode xlvbahowto xlvbainfo OffVBA 
Version           : MACINTOSH:98
Platform          : MACINTOSH
Issue type        : kbhowto

Last Reviewed: May 18, 1999