Pratik Gujarathi
Pratik Gujarathi

Reputation: 768

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

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?

Upvotes: 6

Views: 46772

Answers (7)

Ahmed Mohamed
Ahmed Mohamed

Reputation: 1

MsgBox([Put Your Text Here], MsgBoxStyle.Information & MessageBoxOptions.RightAlign)

I Trid and Its Work

Upvotes: -2

Randolph Brock
Randolph Brock

Reputation: 9

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.

Upvotes: -1

Serch
Serch

Reputation: 11

you probably can use a combinatrion vbtab and controlchars.CrLf in the message box.

Upvotes: 1

Omar Luján
Omar Luján

Reputation: 49

no, but you can cheat by using spaces.

msgbox("                your message")

Upvotes: 4

klausnrooster
klausnrooster

Reputation: 560

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.

Upvotes: 2

Deanna
Deanna

Reputation: 24273

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.

Upvotes: 8

Fionnuala
Fionnuala

Reputation: 91356

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.

Upvotes: 1

Related Questions