Microsoft Office Tutorials and References
In Depth Information
Emulating the MsgBox Function
Here’s the code that I used to execute the function:
Prompt = “You have chosen to save this workbook” & vbCrLf
Prompt = Prompt & “on a drive that is not available to” & vbCrLf
Prompt = Prompt & “all employees.” & vbCrLf & vbCrLf
Prompt = Prompt & “OK to continue?”
Buttons = vbQuestion + vbYesNo
Title = “We have a problem”
Ans = MyMsgBox(Prompt, Buttons, Title)
This example, of course, doesn’t really wipe out your entire hard drive.
How the MyMsgBox function works
Notice the use of four Public variables. The first three ( Prompt1 , Buttons1 , and Title1 )
represent the arguments that are passed to the function. The other variable ( UserClick )
represents the values returned by the function. The UserForm_Initialize procedure needs a way
to get this information and send it back to the function, and using Public variables is the only
way to accomplish that.
The UserForm (shown in Figure 15-12) contains four Label controls. Each of these Label
controls has an image, which I pasted into the Picture property. The UserForm also has three
CommandButton controls and a TextBox control.
I originally used Image controls to hold the four icons, but the images displayed with a
faint outline. I switched to Label controls because the image is not displayed with an
outline.
The code in the UserForm_Initialize procedure examines the arguments and does the
following:
h Determines which, if any, image to display (and hides the others)
h Determines which button(s) to display (and hides the others)
h Determines which button is the default button
h Centers the buttons in the dialog box
h Determines the captions for the CommandButtons
h Determines the position of the text within the dialog box
h Determines how wide to make the dialog box (by using an API function call to get the
video resolution)
 
Search JabSto ::




Custom Search