Vba- Find Center Of Userform

AsifShah

Board Regular
Joined
Feb 12, 2021
Messages
71
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
Hello EveryOne,

Need Help, when userform1 open it show in full screen after open userform Frame1 will show in Center of Userform

Userform Full Screen Code working Fine but need Frame1 on Center of Userform VBA Code.

Application.WindowState = xlMaximized
With Me
.Height = Application.Height
.Width = Application.Width
.Top = 0
.Left = 0
End With
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi There

Try the below code in the Userform Initialize event...

VBA Code:
Private Sub UserForm_Initialize()
    Application.WindowState = xlMaximized
    With Me
        .Height = Application.Height
        .Width = Application.Width
        .Top = 0
        .Left = 0
    End With
    With Frame1
        .Left = (Me.InsideWidth - .Width) / 2
        .Top = (Me.InsideHeight - .Height) / 2
    End With
End Sub
 
Upvote 0
Solution
Hi There

Try the below code in the Userform Initialize event...

VBA Code:
Private Sub UserForm_Initialize()
    Application.WindowState = xlMaximized
    With Me
        .Height = Application.Height
        .Width = Application.Width
        .Top = 0
        .Left = 0
    End With
    With Frame1
        .Left = (Me.InsideWidth - .Width) / 2
        .Top = (Me.InsideHeight - .Height) / 2
    End With
End Sub
Thanks Dear Jimmypop :love: Code working Perfect.

 
Upvote 0
Hi There

Try the below code in the Userform Initialize event...

VBA Code:
Private Sub UserForm_Initialize()
    Application.WindowState = xlMaximized
    With Me
        .Height = Application.Height
        .Width = Application.Width
        .Top = 0
        .Left = 0
    End With
    With Frame1
        .Left = (Me.InsideWidth - .Width) / 2
        .Top = (Me.InsideHeight - .Height) / 2
    End With
End Sub
Hi Jimmy! I have a question: is it possible to make the "Me." to become a variable? My idea is to have the calculations on a module and keep the initialize event with a simple call to the module like this:

VBA Code:
Private Sub UserForm_Initialize()
   Call CalculateWindow
End Sub

Thanks!
 
Upvote 0
Hi Jimmy! I have a question: is it possible to make the "Me." to become a variable? My idea is to have the calculations on a module and keep the initialize event with a simple call to the module like this:

VBA Code:
Private Sub UserForm_Initialize()
   Call CalculateWindow
End Sub

Thanks!

Hi there...

Not sure of this one... But I did read somewhere that you can declare variable using Dim as Object... might be mistaken... My suggestion would be to start a new thread with part of your question as the heading... doing this would have maybe someone with an answer better see it😎
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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