Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 271
Default Center Userform Controls

I am using the following code to make the userform fill the entire screen:

Private mlAppWindowState As Long
Private Sub UserForm_Initialize()
With Application
mlAppWindowState = .WindowState
.WindowState = xlMaximized
Me.Move .Left, .Top, .Width, .Height
End With
End Sub
Private Sub UserForm_Terminate()
Application.WindowState = mlAppWindowState
End Sub


What I need is VBA to center the userform controls. Maybe I could put the
controls inside a frame and I just need to the frame to center. I am not
sure. But I need VBA to position the controls. Can someone get me started?


--
Thanks
Shawn
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Center Userform Controls

Just do something like

With Me
.cmdOK.Left = .Width \ 2 - .cmdOK.Width \ 2
.cmdQuit.Left = .Width \ 2 - .cmdQuit.Width \ 2
End With


in the form activate event

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Shawn" wrote in message
...
I am using the following code to make the userform fill the entire screen:

Private mlAppWindowState As Long
Private Sub UserForm_Initialize()
With Application
mlAppWindowState = .WindowState
.WindowState = xlMaximized
Me.Move .Left, .Top, .Width, .Height
End With
End Sub
Private Sub UserForm_Terminate()
Application.WindowState = mlAppWindowState
End Sub


What I need is VBA to center the userform controls. Maybe I could put the
controls inside a frame and I just need to the frame to center. I am not
sure. But I need VBA to position the controls. Can someone get me
started?


--
Thanks
Shawn



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Center Userform Controls

the controls have top, left, width and height properties as well, Just
calculate where you want them and then set those attributes.

To get the middle of the form, divide the width in half and add it the left
position. Subtract half the width of the control to get the left position
for the control. Use logic related to that to calculate where you want you
controls.

--
Regards,
Tom Ogilvy


"Shawn" wrote:

I am using the following code to make the userform fill the entire screen:

Private mlAppWindowState As Long
Private Sub UserForm_Initialize()
With Application
mlAppWindowState = .WindowState
.WindowState = xlMaximized
Me.Move .Left, .Top, .Width, .Height
End With
End Sub
Private Sub UserForm_Terminate()
Application.WindowState = mlAppWindowState
End Sub


What I need is VBA to center the userform controls. Maybe I could put the
controls inside a frame and I just need to the frame to center. I am not
sure. But I need VBA to position the controls. Can someone get me started?


--
Thanks
Shawn

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 271
Default Center Userform Controls

I used this code, for example, and it worked great.

usfWorkOrder.Label1.Left = (usfWorkOrder.Width) / 2


--
Thanks
Shawn


"Tom Ogilvy" wrote:

the controls have top, left, width and height properties as well, Just
calculate where you want them and then set those attributes.

To get the middle of the form, divide the width in half and add it the left
position. Subtract half the width of the control to get the left position
for the control. Use logic related to that to calculate where you want you
controls.

--
Regards,
Tom Ogilvy


"Shawn" wrote:

I am using the following code to make the userform fill the entire screen:

Private mlAppWindowState As Long
Private Sub UserForm_Initialize()
With Application
mlAppWindowState = .WindowState
.WindowState = xlMaximized
Me.Move .Left, .Top, .Width, .Height
End With
End Sub
Private Sub UserForm_Terminate()
Application.WindowState = mlAppWindowState
End Sub


What I need is VBA to center the userform controls. Maybe I could put the
controls inside a frame and I just need to the frame to center. I am not
sure. But I need VBA to position the controls. Can someone get me started?


--
Thanks
Shawn

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default Center Userform Controls

Shawn,
There are various resizer classes out there, most designed for VB5/6 forms
rather than VBA userforms, but you could edit to suit. e.g.
http://www.dutchthewiz.com/vb/api/

NickHK

"Shawn" ...
I am using the following code to make the userform fill the entire screen:

Private mlAppWindowState As Long
Private Sub UserForm_Initialize()
With Application
mlAppWindowState = .WindowState
.WindowState = xlMaximized
Me.Move .Left, .Top, .Width, .Height
End With
End Sub
Private Sub UserForm_Terminate()
Application.WindowState = mlAppWindowState
End Sub


What I need is VBA to center the userform controls. Maybe I could put the
controls inside a frame and I just need to the frame to center. I am not
sure. But I need VBA to position the controls. Can someone get me
started?


--
Thanks
Shawn





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
userform to appear in the center of the screen JLGWhiz Excel Programming 1 December 28th 06 05:50 AM
userform to appear in the center of the screen JMay Excel Programming 0 December 23rd 06 09:58 PM
mutlipage in the center of userform Pierre via OfficeKB.com[_2_] Excel Programming 1 November 4th 05 08:49 AM
UserForm position other than center of the screen. Jay Fincannon Excel Programming 1 January 23rd 05 02:23 AM
textbox in userform(vertical center) tom taol Excel Programming 0 January 22nd 05 08:11 AM


All times are GMT +1. The time now is 06:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"