VBA/Excel/Access/Word/Application/Dialogs
Содержание
- 1 cancel a procedure if the user clicked the Cancel button in a dialog box:
- 2 Display one of Excel"s built-in dialog boxes and let the user make the choices: by using the Application object"s Dialogs property.
- 3 Returning the Button the User Chose in a Dialog Box
- 4 Set the contents of the File Name text box in the Save As dialog box in Word and then display the dialog box
- 5 Specifying a Timeout for a Dialog Box
- 6 To display Excel"s Open dialog box
- 7 Using an Application"s Built-in Dialog Boxes from VBA: wdDialogFileOpen
cancel a procedure if the user clicked the Cancel button in a dialog box:
<source lang="vb">
Sub dlg()
If Dialogs(wdDialogFileOpen).show = 0 Then End
End Sub
</source>
Display one of Excel"s built-in dialog boxes and let the user make the choices: by using the Application object"s Dialogs property.
<source lang="vb">
Sub show()
Result = Application.Dialogs(xlDialogFormulaGoto).show
End Sub
</source>
Returning the Button the User Chose in a Dialog Box
<source lang="vb">
Return Value Button Clicked -2 Close -1 OK 0 Cancel 1 The first command button 2 The second command button >2 Subsequent command buttons
</source>
Set the contents of the File Name text box in the Save As dialog box in Word and then display the dialog box
<source lang="vb">
Sub show()
With Dialogs(wdDialogFileSaveAs) .Name = "Yellow Paint Primer" .show End With
End Sub
</source>
Specifying a Timeout for a Dialog Box
<source lang="vb">
Sub dlg2()
With Dialogs(wdDialogToolsOptions) .DefaultTab = wdDialogToolsOptionsTabUserInfo .show (15000) End With
End Sub
</source>
To display Excel"s Open dialog box
<source lang="vb">
Sub showDialog()
Application.Dialogs(xlDialogOpen).show
End Sub
</source>
Using an Application"s Built-in Dialog Boxes from VBA: wdDialogFileOpen
<source lang="vb">
Sub box()
If Documents.Count = 0 Then Proceed = MsgBox("no document.Please open a document.", vbOKCancel + vbExclamation, "Format Report") If Proceed = vbOK Then Dialogs(wdDialogFileOpen).Show If Documents.Count = 0 Then End Else End End If End If
End Sub
</source>