Public Sub CenterForm(f As Form, Optional f2 As Variant)
'********************************************************
' Centers a form relative to the screen or
' another form
'********************************************************
If IsMissing(f2) Then
f.Move (Screen.Width - f.Width) / 2, _
(Screen.Height - f.Height) / 2
Else
' If f is an MDI child in a MDI parent then
' center f within the parent.
If f.MDIChild And Not f2.MDIChild Then
f.Move ((f2.Width - f.Width) / 2), _
((f2.Height - f.Height) / 2)
Else
f.Move ((f2.Width - f.Width) / 2) + f2.Left, _
((f2.Height - f.Height) / 2) + f2.Top
End If
End If
End Sub