Home > other >  MsgBox Function
MsgBox Function

Time:01-22

How do I “Call” Vba’s MsgBox function? Is this the same as just using the actual function itself ? I want to make a MsgBox function that returns the date and time

CodePudding user response:

Like this:

MsgBox "It is now " & Format(Now, "yyyy-mm-dd hh:nn"), vbInformation   vbOKOnly, "Current Date and Time"

CodePudding user response:

Is this the same as just using the actual function itself ?

Yes, you may consider it as a regular function in VBA.

I want to make a MsgBox function that returns the date and time

The MsgBox function is for displaying questions or warnings and etc. to users and returning answers like Yes, No, Cancel and etc. Strictly speaking the function displays a message in a dialog box, waits for the user to click a button, and returns an Integer indicating which button the user clicked.

If you need to let users enter any information on on the dialog box you need to use the InputBox function instead. It displays a prompt in a dialog box, waits for the user to input text or click a button, and returns a String containing the contents of the text box. You may then parse the date entered on the dialog box and use it in the code. For example:

Dim Message, Title, Default, MyValue
Message = "Enter a value between 1 and 3"    ' Set prompt.
Title = "InputBox Demo"    ' Set title.
Default = "1"    ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)

' Display dialog box at position 100, 100.
MyValue = InputBox(Message, Title, Default, 100, 100)
  • Related