VB's MsgBox can be centered on a form rather than the screen, but it involves a bit of a hack. You are probably better off following the advice given above to create you own messagebox form.
However, if you want to try the hack, here's a version of it. You'll need a project with a Form and a module. Drop the following code into the module:
[tt]
Option Explicit
' Necessary constants for hooking
Private Const HCBT_ACTIVATE = 5
Public Const WH_CBT = 5
' Working variables that require global scope in hooking module
Private hHook As Long
' The API declarations we need
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOACTIVATE = &H10
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private CallingForm As Form
' Our wrapper for the normal MsgBox function takes an additional optional
' parameter that allows us to specify the form we want the msgbox centred
' over
Public Function vbMsgBox(frmCallingForm As Form, Prompt As String, Optional Buttons As VbMsgBoxStyle = vbOKOnly, Optional Title As String, Optional HelpFile As String, Optional Context As Long) As Long
Set CallingForm = frmCallingForm
hHook = SetWindowsHookEx(WH_CBT, AddressOf WinProc, App.hInstance, 0)
vbMsgBox = MsgBox(Prompt, Buttons, Title, HelpFile, Context)
End Function
Private Function WinProc(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim rectForm As RECT
Dim rectMsg As RECT
Dim x As Long, y As Long
If lMsg = HCBT_ACTIVATE Then
' Get the coordinates of the form and the message box so that
' you can determine where the center of the form is located
GetWindowRect CallingForm.hwnd, rectForm
GetWindowRect wParam, rectMsg
x = (rectForm.Left + (rectForm.Right - rectForm.Left) / 2) - ((rectMsg.Right - rectMsg.Left) / 2)
y = (rectForm.Top + (rectForm.Bottom - rectForm.Top) / 2) - ((rectMsg.Bottom - rectMsg.Top) / 2)
' Position the msgbox
SetWindowPos wParam, 0, x, y, 0, 0, SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE
' Release the CBT hook
UnhookWindowsHookEx hHook
End If
WinProc = False
End Function
[/tt]
Now add a command button to your form, and drop in the following code:
[tt]
Option Explicit
Private Sub Command1_Click()
vbMsgBox Me, "This message box is centered over Form1."
End Sub