MessageBox

An alternative Message Box Modal Dialog with Lightbox for Excel

Version 1.2
10Mar 2017

MessageBox Documentation

By: Mark Kubiszyn


MessageBox for Excel Screenshot



Here is an alternative Modal Dialog Message Box (MsgBox) with LightBox for Excel. You can display messages and capture the respective Buttons that have been pressed ie. vbOK/vbCancel/vbAbort. You can capture user input using message prompts. MessageBox can be configured to display different Buttons and can use HTML Formatting for the main Message

FEATURES

- create messages with a lightbox effect
- capture the return values of the Buttons and / or an abort by closing the dialog or clicking anywhere on the lightbox
- map Buttons to different Text
- change the Message Container, Message Background & Message Font Colours in the Initialise() Subroutine
- change the Dialog Title Colours
- change the Dialog Title, Message Title and Message Font Sizes
- use HTML formatting for the Message
- capture return values using a 'Prompt' style Dialog
- run multiple Message Boxes in unison
- hide the Close Button
- change the Height of the Message Box UserForm
- the HTML, CSS & Javascript shows you how to:
  prevent F5 and CTRL+F5 from being pressed
  prevent the Right-click context menu from being displayed
  prevent Text Selections for specific HTML elements
  remove all scrollbars from a WebBrowser Control
  use Hover with the IE7 WebBrowser


REQUIRED

Excel 2010 or Excel 2013 (32bit or 64bit), working with Windows 7 & 10
Some knowledge of VBA to Copy & Paste Code into respective Code Modules in your own Projects. More advanced users could really 'Pimp' this Project up!

Configuring MessageBox - A Handful of Simple Settings

Configuring MessageBox is straightforward. Here is the Code to create a simple Message with an OK Button:

 
    ' // initialise
    MessageBox.Initialise

    ' // do stuff...

    ' // raise a Prompt MessageBox
    Dim vbResult As VbMsgBoxResult
    vbResult = MessageBox.DisplayMessage(DialogType:=vbMessageDialog, _
																			 DialogTitle:="MessageBox", _
									                                         MessageTitle:="", _
									                                         Message:="Here's a Message!", _
									                                         Buttons:="vbOK", _
									                                         ButtonCaptions:="OK")
 

MessageBox Simple
Or even simpler without using the Name Properties:
 
    MessageBox.Initialise
    MessageBox.DisplayMessage vbMessageDialog, "MessageBox", "", "Here's a Message!", "vbOK", "OK"
 
You can use Initialise() to pass additional settings like this to set the Colour of the Dialog Title:
 
    MessageBox.Initialise DialogTitleBackgroundColour:="#77A8D1"
    MessageBox.DisplayMessage vbMessageDialog, "MessageBox", "", "Here's a Message!", "vbOK", "OK"
 

MessageBox with Blue Dialog Title
You can Prompt the user to enter values and capture the returned data like this:
 
    ' // initialise
    MessageBox.Initialise

    ' // do stuff...

    ' // raise a Prompt MessageBox
    Dim vbResult As VbMsgBoxResult
    Dim strPrompt As String
    vbResult = MessageBox.DisplayMessage(DialogType:=vbPromptDialog, _
                                         									 DialogTitle:="MessageBox", _
									                                         MessageTitle:="", _
									                                         Message:="Please enter a value for the Setting", _
									                                         Buttons:="vbOK|vbCancel", _
									                                         ButtonCaptions:="OK|Cancel", _
									                                         Prompt:=strPrompt)

    ' // use the return result as required
    If vbResult = vbOK Then
        'vbOK
        If strPrompt <> "" Then MsgBox "You entered: " & strPrompt
    End If
 

MessageBox Prompt
You can use HTML Formatting to change the Font Sizes, Font Colours and Styles:
 
    MessageBox.Initialise DialogTitleBackgroundColour:="#77A8D1"
    MessageBox.DisplayMessage vbMessageDialog, "MessageBox", "", "Oops...
Something went wrong!", "vbOK", "OK"  

MessageBox HTML, CSS & Javascript
You can change the LightBox to be a White LightBox and map the Buttons to different Text:
 
    ' - change this to use a Black LightBox or a White LightBox (LightBox UserForm Settings)
    Private Const lngLightBoxColour As Long = vbWhite



    ' // initialise
    MessageBox.Initialise

    ' // do stuff...

    ' // raise a Prompt MessageBox
    Dim vbResult As VbMsgBoxResult
    vbResult = MessageBox.DisplayMessage(DialogType:=vbMessageDialog, _
                                         									 DialogTitle:="MessageBox", _
				 		  												     MessageTitle:="", _
									                                         Message:="Here's a Message!", _
									                                         Buttons:="vbOK|vbCancel", _
                   										                     ButtonCaptions:="Agree|Disagree")

    ' // use the return result as required
    If vbResult = vbOK Then
        'vbOK
        MsgBox "You clicked the Agree Button"
    ElseIf vbResult = vbCancel Then
        'vbCancel
        MsgBox "You clicked the Disagree Button"
    ElseIf vbResult = vbAbort Then
        'vbAbort
        MsgBox "You aborted or closed the Dialog"
    End If
 

MessageBox WHite LightBoxt

Copying the Code into Your Own Projects

To use MessageBox in your own Projects, you can simply start a Project from scratch using the MessageBox Workbook (you can remove the 'License' Worksheet as long as the Code Attributions remain in situ) or you can Export the 2 UserForm .BAS Files from the MessageBox Workbook and then Import them back into your own Project. Then use the examples that accompany the Software or one of the examples above

CHANGELOG

10.03.2017 - (Version 1.2). Adjust the Width of the HTML to the same Width as the UserForm. Adjust the Width & Height of the Markup WebBrowser Control to the same Width & Height (including passed Height) as the MessageBox UserForm. Added an example of how to change the Message Background Colour using HTML - limited to the tag. Added the ability to set the Container, Message Font Colour & Message Background Colours in the MessageBox.Initialise() Subroutine

13.11.2016 - (Version 1.1). Removed the DialogFont parameter of the Initialise() Method as it was not being used. Added an Optional Height parameter to change the Dialog Height. Added an Optional HideCloseButton parameter to enable the user to hide the Close Cross for the Message Box. Added two new examples. Miscellaneous Code tweaks and clean up

01.11.2016 - (Version 1) released