目录

Callback 属性

优质
小牛编辑
124浏览
2023-12-01

设置在显示非模态气球时运行的过程的名称。String 类型,可读写。

说明

根据使用属性的不同,由Callback 属性所指定的回调过程必须接受两到三个参数。如果在向导中用Callback 属性,该过程必须接受两个参数:一个长整型参数,代表用户单击按钮的msoBalloonButtonType 值;另一个长整型参数作为该气球的唯一标识。如果对非模态气球用Callback 属性,该回调过程必须接受三个参数:调用过程的Balloon 对象;一个长整型参数,表示用户单击按钮的msoBalloonButtonType 值;另一个长整型参数作为调用此回调过程的气球的唯一标识,该值在气球的Private 属性中指出。

在传递给回调过程的Balloon 对象中,至少应用了一个Close 方法作为退出条件;否则将不能取消此非模态气球。

如果指定的回调函数存储在单独的类模块中,在Callback 属性的值中必须包含模块名(例如:“Sheet1.MyCallback”)。

示例

本示例可实现的功能为:显示这样一个气球,该气球包含分别代表三台打印机的按钮。无论何时,只要用户单击其中任何按钮,ProcessPrinter 回调进程即开始运行,而该气球关闭。

Sub selectPrinter()
Set bln = Assistant.NewBalloon
With bln
 .Heading = "Select a Printer."
 .Labels(1).Text = "Network Printer"
 .Labels(2).Text = "Local Printer"
 .Labels(3).Text = "Local Color Printer"
 .BalloonType = msoBalloonTypeButtons
 .Mode = msoModeModeless
 .Callback = "ProcessPrinter"
 .Show
End With
End Sub

Sub ProcessPrinter(bln As Balloon, lbtn As Long, _
 lPriv As Long)
 Assistant.Animation = msoAnimationPrinting
 Select Case lbtn
 Case -1
 ' Insert network printer-specific code.
 Case -2
 ' Insert local printer-specific code.
 Case -3
 ' Insert color printer-specific code.
 End Select
 bln.Close
End Sub