Full screen userform -> How do I automatically center a Frame?

Maurush

New Member
Joined
Feb 9, 2011
Messages
42
I know that it is possible to let your userform adapt to fullscreen and that it doesn't matter
what resolution you have, with the following code:

Code:
Private Sub UserForm_Initialize()

    With Me
       .Width = Application.UsableWidth
       .Height = Application.UsableHeight
    End With

End Sub

I want to know if I can center a frame in this userform automatically?!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I'm not certain what you mean by "frame", but assume that you mean an object.

An object can be centered with a computation based upon it, width, height, and the userform size.
 
Upvote 0
Try...

<font face=Calibri><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> UserForm_Initialize()<br><br>    <SPAN style="color:#00007F">With</SPAN> Me<br>        .Width = Application.UsableWidth<br>        .Height = Application.UsableHeight<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <br>    <SPAN style="color:#00007F">With</SPAN> Me.Frame1<br>        .Top = (Me.InsideHeight / 2) - (.Height / 2)<br>        .Left = (Me.InsideWidth / 2) - (.Width / 2)<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>

Change the name of the frame, accordingly.
 
Upvote 0
Try...

Private Sub UserForm_Initialize()

With Me
.Width = Application.UsableWidth
.Height = Application.UsableHeight
End With

With Me.Frame1
.Top = (Me.InsideHeight / 2) - (.Height / 2)
.Left = (Me.InsideWidth / 2) - (.Width / 2)
End With

End Sub


Change the name of the frame, accordingly.

Thank you very much, this worked!
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top