can a userform be 'locked' into position

M

Mike H

Hi,

Try this, Right click your userform, view code and paste this in. You don't
need the message box but it serves to terminate the drag instantly and stops
the userform flashing about. Try it without.

Option Explicit
Private Type position
Left As Single
Top As Single
End Type

Private Sub UserForm_Layout()
Static Pos As position
Dim Moved As Boolean
If Pos.Left = 0 Or Pos.Top = 0 Then
Pos.Left = Me.Left
Pos.Top = Me.Top
Exit Sub
End If
Moved = False
If Me.Left <> Pos.Left Then
Me.Left = Pos.Left
Moved = True
End If
If Me.Top <> Pos.Top Then
Me.Top = Pos.Top
Moved = True
End If
If Moved = True Then
MsgBox "Can't do that"
End If
End Sub

Mike
 
A

Anthony

Hi Mike and thanks for help

the inserted code comes back with an error and stops on this line

Static Pos As position

any ideas?

thanks
 
M

Mike H

Hi,

Did you paste this bit in? It need all of the code if not it will give a

user defined type not defined error

Option Explicit
Private Type position
Left As Single
Top As Single
End Type

Mike
 
A

Anthony

Hi Mike,
yep that has locked the userform, however if I drag the scroll bar accross
the worksheet the form still moves. I want it locked so that it stays in
place - almost locked to a cell range for example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top