Share via


Using Balloon Controls

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

You add labels or check box controls to a Balloon object by using the Balloon object's Labels or Checkboxes property, respectively. (Note that label controls in Balloon objects are similar to option button controls.) You specify the text associated with a label or check box by using the control's Text property. You specify a single control by using an index number between 1 and 5, which represents the number of the label or check box control in the balloon. For example, the following sample shows one way to use label controls in a Balloon object:

With balBalloon
   .Button = msoButtonSetNone
   .Heading = "Balloon Object Example One"
   .Labels(1).Text = "VBA is a powerful programming language."
   .Labels(2).Text = "Office is a great development environment."
   .Labels(3).Text = "The Assistant is cool!"
   .Labels(4).Text = "Balloon objects are easy to use."
   .Text = "Select one of the following "_
       & .Labels.Count & "Options:"

   ' Show the balloon.
   intRetVal = .Show

   ' Save the selection made by the user.
   If intRetVal > 0 Then
      strChoice = "{cf 4}" & .Labels(intRetVal).Text & "{cf 0}"
   Else
      strChoice = ""
   End If
End With

Set balBalloon = Assistant.NewBalloon
With balBalloon
   .Text = "You selected option " & CStr(intRetVal) & ": '" _
      & strChoice & "'"
   .Show
End With

Note that when the balloon is displaying label controls, you are not required to have OK or Cancel buttons, because the balloon is dismissed as soon as any label control is selected, and the user can select only one control at a time. This is not the case when you use check box controls. The user can select more than one check box before dismissing the balloon, so your code should account for multiple selections. The next example shows one way to display check box controls and then identify the selections made by the user:

With balBalloon
   .Button = msoButtonSetOK
   .Heading = "Balloon Object Example Two"
   .Checkboxes(1).Text = "VBA is a powerful programming language."
   .Checkboxes(2).Text = "Office is a great development environment."
   .Checkboxes(3).Text = "The Assistant is cool!"
   .Checkboxes(4).Text = "Balloon objects are easy to use."
   .Text = "How many of the following " _
      & .Checkboxes.Count & " statements do you agree with?"
   ' Save the selection made by the user.
   intRetVal = .Show
   ' Construct the string to display to the user based on the
   ' user's selections.
   For Each chkBox In .Checkboxes
      If chkBox.Checked = True Then
         strChoice = strChoice & "{cf 4}" & chkBox.Text & "{cf 0}" & "' and '"
      End If
   Next chkBox
   ' Remove the trailing "' and '" from strChoice.
   If Len(strChoice) <> 0 Then
      strChoice = Left(strChoice, Len(strChoice) - 7)
   End If
End With

' Create new Balloon object and display the user's choices.
Set balBalloon = Assistant.NewBalloon
With balBalloon
   If intRetVal > 0 Or Len(strChoice) > 0 Then
      .Text = "You selected '" & strChoice & "'."
   Else
      .Text = "You didn't make a selection."
   End If
   .Show
End With

See Also

Working with Shared Office Components | Working with the Office Assistant | Microsoft Agent ActiveX Control vs. the Office Assistant | Programming the Office Assistant | Working with Balloon Objects | Modeless Balloons and the Callback Property