Fixing userform in the center of application and disable moving it

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
554
Currently I have a button that when clicked it opens opens the userform in the center of the screen regardless of dual monitors or not. Now I want to keep it so that the userform is not movable.

The code to center is shown below:

Code:
Sub StartNewUserform()

'   Displays on top of semi-transparent UserForm
    With Userform1
        .StartUpPosition = 0
        .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
        .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
        .Show
    End With


    Unload Me
End Sub

[code]

So what property would allow me to make sure its not movable and even better is there also a way to remove the window frame from the userform that has the caption and x button?

Thanks
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

CalcSux78

Well-known Member
Joined
Oct 15, 2013
Messages
1,120
Code:
Private Sub UserForm_Layout()
Dim iLeft%
Dim iTop%


iLeft = .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
iTop = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
If Not Me.Top = iTop Or Not Me.Left = iLeft Then
    Me.Top = iTop
    Me.Left = iLeft
[COLOR=#008000]    'MsgBox "Ouch"[/COLOR]
End If
End Sub


Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
    Cancel = True
    MsgBox "The X is disabled, please use a button on the form.", vbCritical
End If
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,216
Messages
5,594,885
Members
413,947
Latest member
gizmolucy

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
Top