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?
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")
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.
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.
you probably can use a combinatrion vbtab and controlchars.CrLf in the message box.
It is easy to "center" an Application.Input box: When the box opens, with the mouse move the box where you want it to open in the future and it does just that. It opens where you last position it. At least that; what it does for me.
MsgBox([Put Your Text Here], MsgBoxStyle.Information & MessageBoxOptions.RightAlign)
I Trid and Its Work
MsgBoxStyle.Information
or MessageBoxOptions.RightAlign
in VBA/VB6. And in VB.NET, the expression MsgBoxStyle.Information & MessageBoxOptions.RightAlign
is a string concatenation of the two numbers rather than their binary union. And even if we suspend the disbelief and assume this was C#, that would still need to be |
, not &
. –
Venomous © 2022 - 2024 — McMap. All rights reserved.