https://github.com/cristianbuse/VBA-MessageBox
A custom message box that allows any label on up to 5 buttons
https://github.com/cristianbuse/VBA-MessageBox
Last synced: 4 months ago
JSON representation
A custom message box that allows any label on up to 5 buttons
- Host: GitHub
- URL: https://github.com/cristianbuse/VBA-MessageBox
- Owner: cristianbuse
- License: mit
- Created: 2022-10-19T20:45:59.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-21T09:56:04.000Z (about 1 year ago)
- Last Synced: 2024-08-13T07:18:16.647Z (8 months ago)
- Language: VBA
- Size: 166 KB
- Stars: 4
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - cristianbuse/VBA-MessageBox - A custom message box that allows any label on up to 5 buttons (VBA)
README
# VBA-MessageBox
A custom message box that allows up to 5 buttons with custom labels.
Extra abilities provided by ```MessageBox``` that the built-in ```MsgBox``` method does not provide:
1. Can display up to 5 buttons with custom labels and will return the label of the selected button
2. Displays a vertical scroll bar when the text is too large
3. The main text prompt can be selected and copied (displayed in a locked textbox within the form)
4. The buttons get automatically resized and positioned based on how many buttons are displayed and how long their labels areNote that Cancel is allowed via the form's X button or via the Esc key if the form displays a single button or 'Cancel' is one of the button labels.
## Implementation
The class ```MessageBox``` creates an instance of the ```MessageForm``` userform and then adds all the necessary controls at runtime. It only exposes the ```Show``` method which allows the user to pass:
- the text for prompt
- the title
- the icon enum which corresponds to one of the 4 available icons
- the label(s) for up to 5 buttons
- the index of the default buttonTo remove the need for creating new instances, the class ```MessageBox``` has a global instance (```Attribute VB_PredeclaredId = True```). The exposed ```Show``` method is marked as a default member. It can be called like:
```VBA
Debug.Print MessageBox("Test", "Title", icoInformation, "Button1", "Button2")
```
New instances of the ```MessageBox``` class can still be created but the approach used (global instance with default member) is more convenient.The 4 icons (Critical, Exclamation, Information and Question) are the same as in the original ```MsgBox``` and they are saved in the ```Picture``` property of 4 labels situated on the ```MessageForm``` userform. The form only raises the ```QueryClose``` event. There is no other code within the form.
## Installation
Please avoid copy-pasting code. Either clone the repository or download the [zip](https://github.com/cristianbuse/VBA-MessageBox/archive/refs/heads/master.zip) and proceed importing the modules from there.Just import the following code modules in your VBA Project:
* [MessageBox.cls](https://github.com/cristianbuse/VBA-MessageBox/blob/master/src/MessageBox.cls)
* [MessageForm.frm](https://github.com/cristianbuse/VBA-MessageBox/blob/master/src/MessageForm.frm) (you will also need the [MessageForm.frx](https://github.com/cristianbuse/VBA-MessageBox/blob/master/src/MessageForm.frx) when you import the frm)## Demo
Import the following code module from the [demo folder](https://github.com/cristianbuse/VBA-MessageBox/blob/master/src/Demo) in your VBA Project:
* [Demo.bas](https://github.com/cristianbuse/VBA-MessageBox/blob/master/src/Demo/Demo.bas) - run ```DemoMain```There is also a Demo Workbook available for download.
Screenshot examples:

## License
MIT LicenseCopyright (c) 2022 Ion Cristian Buse
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.