Is there a way to align text in a message box in vb or vba?

Is there a way to center text in msgbox in VB or VBA? Does VB have any functionality to do the same?

+4
source share
4 answers

Not. The MsgBox() function is just a wrapper for Windows MessageBox() and, as such, does not have stylistic control over the dialog for the icon.

If you want to change it further, you will need to create your own window and show it.

In Windows Vista +, you can use TaskDialogs , which allow a lot more control.

+7
source

Vba

Some notes: http://access.mvps.org/access/bugs/bugs0035.htm and http://www.tek-tips.com/viewthread.cfm?qid=435428 However, creating your own message box is not so difficult. that solves all your problems.

+1
source

no, but you can cheat using spaces.

 msgbox(" your message") 
+1
source

When you build your lines, you can insert them at the beginning and at the end with spaces to achieve the target length. If you use excel, the rept function is convenient for this purpose.

 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 earlier, if msgbox still doesn't look good, you can use a text box shape object (or other objects) to get the desired effect.

0
source

Source: https://habr.com/ru/post/1394641/


All Articles