Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Terminating Forms

Hello,

I have set up VBA code so that when I terminate a form (press the little X
in the corner) it executes a set of code then reopens the form. This part is
working fine, but when I reopen the form, nothing on the form will work. The
buttons will not respond when clicked and the form cannot be terminated or
close without breaking the code.

I have tried running the form by using the Show function. I have also
Unloaded and Loaded the form prior to running the Show function and nothing
seems to help.

Any ideas would be appreciated.

Thanks

S.S.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 340
Default Terminating Forms

How about not displaying the X in the corner and thus requiring the user to
close the form via a button that has the statement Me.Hide in it? This
retains the userform in memory. The X unloads it from memory. code to hide
the X is:

'this goes at the top of the module:

Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hWnd As Long, _
ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hWnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Const GWL_STYLE = (-16)
Const WS_SYSMENU = &H80000

use in userform:

Private Sub UserForm_Initialize()
'this hides the X on the caption line
Dim hWnd As Long, a As Long

Dim V As Integer
V = CInt(Left(Application.Version, _
InStr(Application.Version, ".")))
'If V = 8 this is Excel 97
If V = 8 Then
hWnd = FindWindow("ThunderXFrame", Me.Caption)
Else
hWnd = FindWindow("ThunderDFrame", Me.Caption)
End If
a = GetWindowLong(hWnd, GWL_STYLE)

SetWindowLong hWnd, GWL_STYLE, a And Not WS_SYSMENU
End Sub

Bob Flanagan
Macro Systems
Delaware, U.S. 302-234-9857
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel

"S. L. S." <S. L. wrote in message
...
Hello,

I have set up VBA code so that when I terminate a form (press the little X
in the corner) it executes a set of code then reopens the form. This part
is
working fine, but when I reopen the form, nothing on the form will work.
The
buttons will not respond when clicked and the form cannot be terminated or
close without breaking the code.

I have tried running the form by using the Show function. I have also
Unloaded and Loaded the form prior to running the Show function and
nothing
seems to help.

Any ideas would be appreciated.

Thanks

S.S.



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
Can you terminate an autorecover save operation w/o terminating EX gcanty Excel Discussion (Misc queries) 1 June 18th 08 09:08 PM
RefEdits and normal forms / forms in a DLL David Welch Excel Programming 0 December 1st 04 03:49 PM
Forms that open from forms Azza Excel Programming 1 October 12th 04 10:54 PM
Calling Forms from Forms - Exit problems Stuart[_5_] Excel Programming 3 May 25th 04 06:50 AM
VBA forms George V Excel Programming 1 September 8th 03 10:35 PM


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

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

About Us

"It's about Microsoft Excel"