PC Review


Reply
Thread Tools Rate Thread

can a userform be 'locked' into position

 
 
Anthony
Guest
Posts: n/a
 
      17th Jul 2008
can a userform be 'locked' into position once displayed?

thanks
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      17th Jul 2008
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

"Anthony" wrote:

> can a userform be 'locked' into position once displayed?
>
> thanks

 
Reply With Quote
 
Anthony
Guest
Posts: n/a
 
      17th Jul 2008
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

"Mike H" wrote:

> 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
>
> "Anthony" wrote:
>
> > can a userform be 'locked' into position once displayed?
> >
> > thanks

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      17th Jul 2008
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

"Anthony" wrote:

> 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
>
> "Mike H" wrote:
>
> > 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
> >
> > "Anthony" wrote:
> >
> > > can a userform be 'locked' into position once displayed?
> > >
> > > thanks

 
Reply With Quote
 
Anthony
Guest
Posts: n/a
 
      17th Jul 2008
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.

"Mike H" wrote:

> 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
>
> "Anthony" wrote:
>
> > 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
> >
> > "Mike H" wrote:
> >
> > > 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
> > >
> > > "Anthony" wrote:
> > >
> > > > can a userform be 'locked' into position once displayed?
> > > >
> > > > thanks

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      17th Jul 2008
Then I hope you get an answer, I don't know how to do that

Mike

"Anthony" wrote:

> 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.
>
> "Mike H" wrote:
>
> > 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
> >
> > "Anthony" wrote:
> >
> > > 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
> > >
> > > "Mike H" wrote:
> > >
> > > > 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
> > > >
> > > > "Anthony" wrote:
> > > >
> > > > > can a userform be 'locked' into position once displayed?
> > > > >
> > > > > thanks

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Position a chart according to the position of the userform Gaetan Microsoft Excel Discussion 2 3rd Mar 2010 04:28 PM
UserForm position =?Utf-8?B?U3RldmU=?= Microsoft Excel Misc 1 26th Aug 2007 04:50 AM
Position of a UserForm MD Microsoft Excel Programming 2 12th Apr 2005 12:29 AM
Userform Position Pete Microsoft Excel Programming 4 20th Feb 2005 12:01 AM
UserForm position Tim Microsoft Excel Programming 2 12th Feb 2004 03:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:26 PM.