目录

Show 方法

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

全部显示

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

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

MsoBalloonButtonType 可以为下列 MsoBalloonButtonType 常量之一。msoBalloonButtonAbortmsoBalloonButtonBackmsoBalloonButtonCancelmsoBalloonButtonClosemsoBalloonButtonIgnoremsoBalloonButtonNextmsoBalloonButtonNomsoBalloonButtonNullmsoBalloonButtonOKmsoBalloonButtonOptionsmsoBalloonButtonRetrymsoBalloonButtonSearchmsoBalloonButtonSnoozemsoBalloonButtonTipsmsoBalloonButtonYesmsoBalloonButtonYesToAll

expression.Show

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

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

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

expression.Show

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

示例

应用于 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