Fixing userform in the center of application and disable moving it

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
562
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
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,893
Messages
5,834,274
Members
430,273
Latest member
Windrunner

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