Microsoft KB Archive/184502

= OFF98: How to Display a Custom Office Assistant Balloon =

Article ID: 184502

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Office 98 for Macintosh

-



This article was previously published under Q184502



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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements.

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:

  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  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. Click OK.

The balloon disappears.

Balloon with a Numbered List
  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.  Click OK to close the balloon.</ol>

Balloon with Check Boxes
  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 </li> Run the Balloon_Checkboxes macro.

A balloon with three check boxes appears.</li> Click one or more check boxes, and then click OK.

Messages boxes that display your choices appear.</li></ol>

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

Multiple Balloons
  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 </li> Run the Balloon_Array macro. The first balloon appears.</li> Click OK in the balloon.

The second balloon appears.</li> Click OK in the balloon.

The second balloon is dismissed.</li></ol>

Performing Actions Based on a Selection
  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 </li> Run the Balloon_Options macro.

A balloon with two options appears.</li> Click "Save your file."

The balloon reappears, and the text in the balloon is "You chose the Save option."</li> Click "Print your file."

The balloon reappears, and the text in the balloon is "You chose the Print option."</li> Click OK to dismiss the balloon.</li></ol>

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.

<div class="references_section">