Msg Box emulation MyMsg Box code

The MyMsgBox function uses a UserForm named MyMsgBoxForm. The function itself, which follows, is very short. The bulk of the work is done in the UserForm_Initialize procedure.

CD- The complete code for the MyMsgBox function is too lengthy to list here, but it's available in ROM a workbook namedĀ® msgbox emulation.xlsm, available on the companion CD-ROM. The workbook is set up so you can easily try various options.

Public Prompt1 As String Public Buttons1 As Integer Public Title1 As String Public UserClick As Integer

Function MyMsgBox(ByVal Prompt As String, _ Optional ByVal Buttons As Integer, _ Optional ByVal Title As String) As Integer Prompt1 = Prompt Buttons1 = Buttons Title1 = Title MyMsgBoxForm.Show MyMsgBox = UserClick End Function

Figure 15-11 shows MyMsgBox in use. It looks very similar to the VBA message box, but I used a different font for the message text (Calibri 12-point bold). /-

We have a problem

You are about to wipe out your hard drive. _ OK to continue?




Figure 15-11: The result of the MsgBox emulation function. Here's the code that I used to execute the function:

Prompt = "You are about to wipe out your entire hard drive."

Prompt = Prompt & vbCrLf & vbCrLf & "OK to continue?"

Buttons = vbQuestion + vbYesNo

Title = "We have a problem"

Ans = MyMsgBox(Prompt, Buttons, Title)

Note This example, of course, does not really wipe out your entire hard drive.

Was this article helpful?

0 0

Post a comment