Remember position of Userform

T

Tony Starr

I want word to remember the position that a userform was in when the user
closed it. When the form is next opened I want to position it in the exact
place that the user moved it to the last time it was open.

Can this be done?
 
J

Jonathan West

Tony Starr said:
I want word to remember the position that a userform was in when the user
closed it. When the form is next opened I want to position it in the exact
place that the user moved it to the last time it was open.

Can this be done?

In principle, yes. At the time the UserForm is closed, save the values of
the Top and Left properties of the form somewhere.

In the Initialize event of the UserForm, read the saved values and apply
them back to the properties. You'll probably want to set some default values
for use when the form is opened for the first time.
 
F

fumei via OfficeKB.com

Not just in principle. Your answer does not need that qualifier. Your
answer is correct. The answer to:

Can this be done?

is yes, it can.

Just to add possible suggestions. Store the Top and Left values as document
Variables. Something like:

Private Sub CommandButton1_Click()

ActiveDocument.Variables("myTop").Value = Me.Top
ActiveDocument.Variables("myLeft").Value = Me.Left

Unload Me
End Sub

When Initializing, check the value of StartUpPosition. Manual = 0, so if it
is NOT set as Manual, it will open "normally". At the end of the following,
StartUpPosition is set for Manual, so the next time it is Initialized
StartUpPosition will be 0, and so the last positions (stored as Variables)
will be used.

Private Sub UserForm_Initialize()
On Error Resume Next
If Me.StartUpPosition = 0 Then
Me.Top = ActiveDocument.Variables("myTop").Value
Me.Left = ActiveDocument.Variables("myLeft").Value
End If
Me.StartUpPosition = 0
End Sub
 
F

fumei via OfficeKB.com

I just want to add that Jonathan's comment re:

"You'll probably want to set some default values for use when the form is
opened for the first time"

has validity, but it may be better to use StartUpPosition, rather than any
hard coded first-time explicit Top/Left. That way, if it is used on a
different machine, or you change screen resolution, it will still work
properly.
Not just in principle. Your answer does not need that qualifier. Your
answer is correct. The answer to:

Can this be done?

is yes, it can.

Just to add possible suggestions. Store the Top and Left values as document
Variables. Something like:

Private Sub CommandButton1_Click()

ActiveDocument.Variables("myTop").Value = Me.Top
ActiveDocument.Variables("myLeft").Value = Me.Left

Unload Me
End Sub

When Initializing, check the value of StartUpPosition. Manual = 0, so if it
is NOT set as Manual, it will open "normally". At the end of the following,
StartUpPosition is set for Manual, so the next time it is Initialized
StartUpPosition will be 0, and so the last positions (stored as Variables)
will be used.

Private Sub UserForm_Initialize()
On Error Resume Next
If Me.StartUpPosition = 0 Then
Me.Top = ActiveDocument.Variables("myTop").Value
Me.Left = ActiveDocument.Variables("myLeft").Value
End If
Me.StartUpPosition = 0
End Sub
[quoted text clipped - 8 lines]
them back to the properties. You'll probably want to set some default values
for use when the form is opened for the first time.
 
T

Tony Starr

Thanks fumei

fumei via OfficeKB.com said:
I just want to add that Jonathan's comment re:

"You'll probably want to set some default values for use when the form is
opened for the first time"

has validity, but it may be better to use StartUpPosition, rather than any
hard coded first-time explicit Top/Left. That way, if it is used on a
different machine, or you change screen resolution, it will still work
properly.
Not just in principle. Your answer does not need that qualifier. Your
answer is correct. The answer to:

Can this be done?

is yes, it can.

Just to add possible suggestions. Store the Top and Left values as
document
Variables. Something like:

Private Sub CommandButton1_Click()

ActiveDocument.Variables("myTop").Value = Me.Top
ActiveDocument.Variables("myLeft").Value = Me.Left

Unload Me
End Sub

When Initializing, check the value of StartUpPosition. Manual = 0, so if
it
is NOT set as Manual, it will open "normally". At the end of the
following,
StartUpPosition is set for Manual, so the next time it is Initialized
StartUpPosition will be 0, and so the last positions (stored as Variables)
will be used.

Private Sub UserForm_Initialize()
On Error Resume Next
If Me.StartUpPosition = 0 Then
Me.Top = ActiveDocument.Variables("myTop").Value
Me.Left = ActiveDocument.Variables("myLeft").Value
End If
Me.StartUpPosition = 0
End Sub
I want word to remember the position that a userform was in when the
user
closed it. When the form is next opened I want to position it in the
exact
[quoted text clipped - 8 lines]
them back to the properties. You'll probably want to set some default
values
for use when the form is opened for the first time.
 
T

Tony Starr

Thanks Jonathan

Jonathan West said:
In principle, yes. At the time the UserForm is closed, save the values of
the Top and Left properties of the form somewhere.

In the Initialize event of the UserForm, read the saved values and apply
them back to the properties. You'll probably want to set some default
values for use when the form is opened for the first time.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
 

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