View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Save Form Position on Close

Hi Jonathan,

By the time I worked out how to do this I see that Dave has already provided
what is probably a solution but thought I would post what I have discovered
anyway. You can use UserForm_Layout event to save the parameters.

To reset the form to the last used position you need to set the forms
StartupPosition property to 0 - Manual and then the code in the Initialize
event as I have written it.

For some reason I was not able to code the Move command using the named
parameters of Left:=, Top:= etc because I kept getting an error but simply
separating the values with a comma and placing them in the correct default
order it works. Perhaps someone can comment on this.


Private Sub UserForm_Layout()
'Saves the forms position, height and width.
Sheets("Sheet1").Range("A1") = Me.Left
Sheets("Sheet1").Range("A2") = Me.Top
Sheets("Sheet1").Range("A3") = Me.Width
Sheets("Sheet1").Range("A4") = Me.Height
End Sub

Private Sub UserForm_Initialize()
'NOTE: Set form property StartupPosition
'to 0 - Manual
'Order of parameters in code is
'Left, Top, Width, Height

UserForm1.Move _
Sheets("Sheet1").Range("A1"), _
Sheets("Sheet1").Range("A2"), _
Sheets("Sheet1").Range("A3"), _
Sheets("Sheet1").Range("A4")

End Sub


Regards,

OssieMac