View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Matthew Herbert[_3_] Matthew Herbert[_3_] is offline
external usenet poster
 
Posts: 149
Default Centralizing a command button on a userform

Roger,

If you know the height and width of your command button, then after you set
the size of your UserForm (with the code you posted), do a little math to get
the center coordinates, do some more math to get the left and top coordiates
for the command button, and set the .Left and .Top properties of the command
button.

(You know half the height and half the width of the UserForm. You also know
half the command button height and half the command button width. The reset
is addition/subtraction).

Best,

Matthew Herbert
"Roger on Excel" wrote:

I have a userform which sizes to the screen using the following code

Private Sub UserForm_Initialize()
With Me
.Height = Application.Height
.Width = Application.Width
.Left = Application.Left
.Top = Application.Top
End With
End Sub

I have a command button on the userform, but I would like it to be always
centered on the page.

Is there a way to do this?

Many thanks,

Roger