View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Robert Crandal Robert Crandal is offline
external usenet poster
 
Posts: 309
Default Userform problem with "Run Time Error 75"

Hi Joel. Thanks for catching that minor function flaw.
Unfortunately, my workbook is still crashing with a Run Time
Error 75 because my Userform1 object seems to keep
vanishing.

I have stripped down my code to only the following which
is placed in my Userform1 code module.
-------------------------------------------------------------------------------
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Const GWL_HWNDPARENT As Long = -8
------------------------------------------------------------------------------
Private Sub UserForm_Initialize()
Dim hWnd As Long
hWnd = FindWindow("ThunderDFrame", Me.Caption)
SetWindowLongA hWnd, GWL_HWNDPARENT, 0&
End Sub
-------------------------------------------------------------------------------
' Module 1
Sub Button1_Click()
Userform1.Show vbModeless
End Sub
------------------------------------------------------------------------------

The problem seems to be the "SetWindowLongA" function call which changes the
window style to GWL_PARENT.

I know that if I get rid of this call to SetWindowLongA that my Userform1
will
never disappear at random times, but I really love having this special popup
window
that remains visible even when Excel is minimized.

Also, the above code works fine on my Windows Vista machine. It only
crashes
on Windows XP, Service Pack 2. Try loading the userform a couple times,
walk away from your computer for about 2-5 minutes after the screen saver
turns
on, then try to load the userform again. That is when I get the message
"Could not find the specified object"

How about if I set the Userform flag back to it's original setting when the
user
closes out or unloads the form??? In other words, how can I change the
window flag from GWL_HWNDPARENT back to it's original setting???
I'm not sure how I would do that??



"joel" wrote in message
...

I think I found the problem. I set bIsLoaded = False in the function
below. Without this statement the function was returing nothing which
may of caused problems with your code.