Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Hiding a "Userform" instead of closing it???

I have a push button on my spreadsheet which loads my Userform
in the following manner:

Sub Button1_Click()
UserForm1.Show (vbModeless) ' Display my Userform
End Sub

When a user presses the "X" button on the Userform object
I believe that Excel will terminate the Userform instead of
simply "hiding" it by making it invisible. How can I program
my Userform to turn invisible instead of terminating itself??

I would rather have the Userform turn invisible so it can
maintain its current position on the screen when it is
re-activated again..... I noticed that the Userform position
gets reset to default after the form is terminated, and I want
to avoid this.

Thank you!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Hiding a "Userform" instead of closing it???

You can hide your form and maintain it in memory until Show'n again. However
if the only reason is to display next time at the previous position far
better to trap the coordinates before unloading, and reapply them when the
form reloads. Try something like this

' normal module
Public gFormLeft As Single
Public gFormTop As Single

Sub test()
UserForm1.Show vbModeless

End Sub

' userform module

Private Sub UserForm_Initialize()

If gFormLeft Or gFormTop Then
With Me
.StartUpPosition = 0
.Left = gFormLeft
.Top = gFormTop
End With
End If

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)

With Me
gFormLeft = .Left
gFormTop = .Top
End With

End Sub

Instead of saving the position to variables you could save them to hidden
cells, or even pop them in the registry (see SaveSetting and GetSetting).

Regards,
Peter T


"Robert Crandal" wrote in message
...
I have a push button on my spreadsheet which loads my Userform
in the following manner:

Sub Button1_Click()
UserForm1.Show (vbModeless) ' Display my Userform End Sub

When a user presses the "X" button on the Userform object
I believe that Excel will terminate the Userform instead of
simply "hiding" it by making it invisible. How can I program
my Userform to turn invisible instead of terminating itself??

I would rather have the Userform turn invisible so it can
maintain its current position on the screen when it is
re-activated again..... I noticed that the Userform position
gets reset to default after the form is terminated, and I want
to avoid this.

Thank you!




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Hiding a "Userform" instead of closing it???

Good, your code is exactly what I was looking for.....

I just have one question about the variables "gFormLeft"
and "gFormTop". The code works great when I place
these variables in the "normal module", but it does NOT
work if I move the variables into the "userform module".
Do you know why this code would not work if I put
these variables into the userform module??? just curious...

It might be a newbie question! 8)

"Peter T" <peter_t@discussions wrote in message
...

You can hide your form and maintain it in memory until Show'n again.
However if the only reason is to display next time at the previous
position far better to trap the coordinates before unloading, and reapply
them when the form reloads. Try something like this

' normal module
Public gFormLeft As Single
Public gFormTop As Single

Sub test()
UserForm1.Show vbModeless

End Sub

' userform module

Private Sub UserForm_Initialize()

If gFormLeft Or gFormTop Then
With Me
.StartUpPosition = 0
.Left = gFormLeft
.Top = gFormTop
End With
End If

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)

With Me
gFormLeft = .Left
gFormTop = .Top
End With

End Sub

Instead of saving the position to variables you could save them to hidden
cells, or even pop them in the registry (see SaveSetting and GetSetting).

Regards,
Peter T


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Hiding a "Userform" instead of closing it???

A userform is a type of Class object that only "exists" when while it is
loaded. That occurs as soon as you refer to it in code, eg with
Userform1.Show. When the form is unloaded it exists no more and any module
level immediately loose scope.

That's a somewhat simplistic explanation, but basically why Userform
variables are lost when the form is destroyed (unloaded).

Regards,
Peter T



"Robert Crandal" wrote in message
...
Good, your code is exactly what I was looking for.....

I just have one question about the variables "gFormLeft"
and "gFormTop". The code works great when I place
these variables in the "normal module", but it does NOT
work if I move the variables into the "userform module".
Do you know why this code would not work if I put
these variables into the userform module??? just curious...

It might be a newbie question! 8)

"Peter T" <peter_t@discussions wrote in message
...

You can hide your form and maintain it in memory until Show'n again.
However if the only reason is to display next time at the previous
position far better to trap the coordinates before unloading, and reapply
them when the form reloads. Try something like this

' normal module
Public gFormLeft As Single
Public gFormTop As Single

Sub test()
UserForm1.Show vbModeless

End Sub

' userform module

Private Sub UserForm_Initialize()

If gFormLeft Or gFormTop Then
With Me
.StartUpPosition = 0
.Left = gFormLeft
.Top = gFormTop
End With
End If

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)

With Me
gFormLeft = .Left
gFormTop = .Top
End With

End Sub

Instead of saving the position to variables you could save them to hidden
cells, or even pop them in the registry (see SaveSetting and GetSetting).

Regards,
Peter T




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Hiding a "Userform" instead of closing it???


Robert Crandal;566072 Wrote:
I have a push button on my spreadsheet which loads my Userform
in the following manner:

Sub Button1_Click()
UserForm1.Show (vbModeless) ' Display my Userform
End Sub

When a user presses the "X" button on the Userform object
I believe that Excel will terminate the Userform instead of
simply "hiding" it by making it invisible. How can I program
my Userform to turn invisible instead of terminating itself??

I would rather have the Userform turn invisible so it can
maintain its current position on the screen when it is
re-activated again..... I noticed that the Userform position
gets reset to default after the form is terminated, and I want
to avoid this.

Thank you!


To answer your original question, put this code in the user form's code
modlue:

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As
Integer)
If CloseMode = 0 Then '(closemode = 0 means x in top right was
clicked)
Cancel = True
Me.Hide
End If
End Sub

The form still exists, controls values too, for when -.show- gets
executed again


--
p45cal

*p45cal*
------------------------------------------------------------------------
p45cal's Profile: http://www.thecodecage.com/forumz/member.php?userid=558
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=156259

Microsoft Office Help

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
How do display a "+" or "-" sign when hiding columns? DTI Tustin Setting up and Configuration of Excel 1 July 13th 06 01:21 PM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
Excel 2000 crashes after "touching" a userform with the mouse and closing it Chris J Mercer Excel Programming 0 October 1st 03 08:41 AM


All times are GMT +1. The time now is 10:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"