Finance

Charts

Statistics

Macros

Search

Dialogfelder  Running the First Example in Excel VBA

To test the dialog box within the Visual Basic Editor (VBE), simply press the F5 key. This works whether you are in the Code view or the Object view of the UserForm.

If you want to launch the dialog box from a worksheet or elsewhere in the workbook, you will need an additional procedure. This procedure should be stored in a standard code module:

Sub ShowDialog()
    frmFirst.Show
    MsgBox "Dialog box closed"
End Sub

Explanation:
The method .Show() loads the dialog box into memory and displays it to the user.

For example, you can link the dialog box display to the Workbook Open event, so it appears automatically when the workbook is opened:

Private Sub Workbook_Open()
    frmFirst.Show
End Sub

Important Notes

This is a modal dialog box, meaning that no other actions in Excel can be performed while the dialog is open. Additionally, any further VBA code following the .Show method in the calling procedure (e.g., in ShowDialog) will only execute once the dialog box has been closed.

This behavior is advantageous because it guides the user through the application in a controlled manner.

It is also possible, though less commonly used, to display a dialog box as modeless by specifying the optional parameter vbModeless when calling .Show. In this case, the user can still interact with the worksheet even while the dialog box is open. For instance, dialog boxes in Word or Excel are sometimes called this way.

Using a modal dialog box forces the user to provide or select certain data first before interacting further with the workbook sheets.

Exporting and Importing

A UserForm module containing a dialog box can be exported and imported just like a standard code module.

The export/import process is explained in detail in section 5.6, « Exporting and Importing Modules. » The main difference is that two files are generated for the UserForm module: one with the extension .frm and another with .frx, whereas a standard code module exports as a single .bas file.

0 0 votes
Évaluation de l'article
S’abonner
Notification pour
guest
0 Commentaires
Le plus ancien
Le plus récent Le plus populaire
Online comments
Show all comments
Facebook
Twitter
LinkedIn
WhatsApp
Email
Print
0
We’d love to hear your thoughts — please leave a commentx