Office VBA教程:Show方法

Show方法应用于 Balloon对象的情形。

显示指定气球对象。返回表示用户单击的气球或标签的MsoBalloonButtonType 常量。只读。

MsoBalloonButtonType 可以为下列 MsoBalloonButtonType 常量之一。
msoBalloonButtonAbort
msoBalloonButtonBack
msoBalloonButtonCancel
msoBalloonButtonClose
msoBalloonButtonIgnore
msoBalloonButtonNext
msoBalloonButtonNo
msoBalloonButtonNull
msoBalloonButtonOK
msoBalloonButtonOptions
msoBalloonButtonRetry
msoBalloonButtonSearch
msoBalloonButtonSnooze
msoBalloonButtonTips
msoBalloonButtonYes
msoBalloonButtonYesToAll

expression.Show

expression   必需。该表达式返回一个 Balloon对象。

Show方法应用于 FileDialog对象的情形。

显示文件对话框并返回一个 Long 类型,表示用户是按下了操作按钮 (-1) 还是取消按钮 (0)。在调用 Show方法时,在用户消除文件对话框之前将不执行任何代码。在“另存为”和“打开”对话框中,在 Show方法后使用 Execute方法执行用户操作。

expression.Show

expression   必需。该表达式返回一个 FileDialog对象。

VBA示例

应用于 Balloon对象的情形。

本示例创建一个气球,包含两个设置打印机方向的气球标签选项:“纵向”和“横向”。本示例在 Select Case 语句中使用 Show方法判断用户选择的方向。


Set balNew = Assistant.NewBalloon
With balNew
    .Heading = "Please choose a printer orientation"
    .Labels(1).Text = "Portrait"
    .Labels(2).Text = "Landscape"
    .Button = msoButtonSetNone
End With
Select Case balNew.Show
    Case 1
        ' Insert code to set printer to Portrait.
    Case 2
        ' Insert code to set printer to Landscape.
End Select

本示例创建包含三个命令按钮的气球:“是”、“否”和“取消”。本示例在 Select Case 语句中使用 Show方法判断用户单击的按钮的返回值。


Set balNew = Assistant.NewBalloon
With balNew
    .Heading = "Are you sure you want to set the " & _
    "printer orientation to Landscape?"
    .BalloonType = msoBalloonTypeButtons
    .Button = msoButtonSetYesNoCancel
End With
Select Case balNew.Show
    Case -2 ' User selected Cancel button.
        returnValue = MsgBox("Operation canceled.", _
        vbOKOnly, "Printer Message")
    Case -3 ' User selected Yes button.
        returnValue = MsgBox("Printer set to " & _
        "Landscape.", vbOKOnly, "Printer Message")
    Case -4 ' User selected No button.
        returnValue = MsgBox("Printer orientation not " & _
        "reset.", vbOKOnly, "Printer Message")
End Select

应用于 FileDialog对象的情形。

本示例使用 FileDialog对象显示“文件选取器”对话框,并在消息框中显示每个选定的文件。


Sub Main()
    'Declare a variable as a FileDialog object.
    Dim fd As FileDialog
    'Create a FileDialog object as a File Picker dialog box.
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    'Declare a variable to contain the path
    'of each selected item. Even though the path is a String,
    'the variable must be a Variant because For Each...Next
    'routines only work with Variants and Objects.
    Dim vrtSelectedItem As Variant
    'Use a With...End With block to reference the FileDialog object.
    With fd
        'Use the Show method to display the File Picker dialog box and return the user's action.
        'The user pressed the action button.
 If .Show = -1 Then
            'Step through each string in the FileDialogSelectedItems collection.
            For Each vrtSelectedItem In .SelectedItems
                'vrtSelectedItem is a string that contains the path of each selected item.
                'You can use any file I/O functions that you want to work with this path.
                'This example simply displays the path in a message box.
                MsgBox "The path is: " & vrtSelectedItem
            Next vrtSelectedItem
        'The user pressed Cancel.
 Else
        End If
    End With
    'Set the object variable to nothing.
    Set fd = Nothing
End Sub

上页:Office VBA教程:SetSortOrder方法 下页:Office VBA教程:ShowPopup方法

Office VBA教程:Show方法

Office VBA教程:ShowPopup方法 Office VBA教程:StartWizard方法
Office VBA教程:Update方法 Office VBA教程:新增方法
Office VBA教程:AnswerWizard对象 Office VBA教程:AnswerWizardFiles集合对象
Office VBA教程:Assistant对象 Office VBA教程:Balloon对象
Office VBA教程:BalloonCheckBox对象 Office VBA教程:BalloonCheckboxes集合对象
Office VBA教程:BalloonLabel对象 Office VBA教程:BalloonLabels集合对象
Office VBA教程:COMAddIn对象 Office VBA教程:COMAddIns集合对象
Office VBA教程:CommandBar对象 Office VBA教程:CommandBarButton对象
Office VBA教程:CommandBarComboBox对象 Office VBA教程:CommandBarControl对象
Office VBA教程:CommandBarControls集合对象 Office VBA教程:CommandBarPopup对象
版权所有 © 中山市飞娥软件工作室 证书:粤ICP备09170368号