Is there any way to align text into the center in msgbox
in VB or VBA? Does VB have any functionality to do the same?
To visually specify the alignment of text inside of one or more cells, give focus to the cell or select the cells. Then, in the Alignment section of the Home tab of the Ribbon, click the desired alignment button.
A MsgBox is nothing but a dialog box that you can use to inform your users by showing a custom message or get some basic inputs (such as Yes/No or OK/Cancel). While the MsgBox dialog box is displayed, your VBA code is halted. You need to click any of the buttons in the MsgBox to run the remaining VBA code.
The VBA MsgBox function is used to display messages to the user in the form of a message box. We can configure the message box to provide the user with a number of different buttons such as Yes, No, Ok, Retry, Abort, Ignore and Cancel. The MsgBox function will then return the button that was clicked.
No. The MsgBox()
function is simply a wrapper for the Windows MessageBox()
function and as such has no stylistic control over the dialog beyond the icon.
If you want to change it any further than this, you will need to create your own window and show that instead.
On Windows Vista+ you can use TaskDialogs that allow a lot more control.
no, but you can cheat by using spaces.
msgbox(" your message")
VBA
Some notes: http://access.mvps.org/access/bugs/bugs0035.htm AND http://www.tek-tips.com/viewthread.cfm?qid=435428 However, it is not so difficult to build your own message box, which solves all your problems.
When you are building your strings you could pad them at the beginning and end with spaces to achieve a target length. If you're using excel the worksheet function rept is handy for this.
function pad_n_center(byval mystring as string, lenmax as integer) as string
dim pad_by as integer
dim pad as string
pad_by = (lenmax - len(mystring))/2
'some more code to finesse that?
pad = worksheetfunction.rept(" ",pad_by)
pad_n_center = pad & mystring & pad
end function
As mentioned before if the msgbox still doesn't look good you can use textbox shape object (or other objects) to get the desired effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With