VBA MsgBox Function

Written by

in

In Visual Basic (VBA, VB.NET, and VBScript), the MsgBox function uses predefined Buttons Constants to control which buttons appear in the dialog box. When a user clicks a button, the function halts the script and returns a specific Integer Value, allowing your program to react to the user’s choice. Button Types and Constants

You can define the button layouts by using either the predefined VB constant name or its exact numeric value: Constant Name Numeric Value Description / Visible Buttons vbOKOnly 0 Displays only the OK button (Default). vbOKCancel 1 Displays OK and Cancel buttons. vbAbortRetryIgnore 2 Displays Abort, Retry, and Ignore buttons. vbYesNoCancel 3 Displays Yes, No, and Cancel buttons. vbYesNo 4 Displays Yes and No buttons. vbRetryCancel 5 Displays Retry and Cancel buttons. Return Values (What Was Clicked)

Your code evaluates the user’s choice by capturing the returned integer: Constant Name Button Clicked vbOK 1 vbCancel 2 vbAbort 3 vbRetry 4 vbIgnore 5 vbYes 6 vbNo 7 Setting a Default Button

If you want a specific button to be highlighted by default when the user presses Enter, you add a default button value to your button type configuration:

Функция MsgBox (Visual Basic для приложений)

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *