Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MsgBox Centering (XP: SP3)

    Is it possible to have the text "Try Again" be automatically centered within the message box?

    If I were to append text to: "Employee ID or Password not recognized." the size of the msgbox would increase however "Try Again" does not move to the right.
    MsgBox "Employee ID or Password not recognized." & Chr(13) & Chr(13) & "Try Again."

    Thanks,
    John

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: MsgBox Centering (XP: SP3)

    I don't think this is possible (unless someone knows how to do this with Windows API functions). You could create a UserForm to act as a custom message box.

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MsgBox Centering (XP: SP3)

    Hans,

    After giving it more thought, I came up with:

    Sub CenterText()
    Set af = Application.WorksheetFunction
    oLine01 = "Employee ID or Password not recognized. Blah Blah"
    oLine02 = "Try Again."

    MsgBox oLine01 & Chr(13) & Chr(13) & _
    af.Rept(" ", (Len(oLine01) / 2 + Len(oLine02) / 2)) & oLine02
    End Sub


    The only challenge I can see is how the font spacing comes into play. It appears the font in the message box is Ariel (?).

    John

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: MsgBox Centering (XP: SP3)

    The font in a message box is set in the Appearance tab of the Display Properties control panel (in Windows XP, click the Advanced button in this tab)

    You'd need to retrieve this font from the registry, and use Windows API functions to get the width of the strings in this font. I'm afraid I can't help you with that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •