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

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
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
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,266
Members
448,558
Latest member
aivin

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