Hi Peter
I seem to get it to work when I change the code as follows:
Sub Reset_EnableEvents_NEW()
'If AppClass Is Nothing Then
' 'Set AppClass = New ClassName
' Set AppClass = New EventClass
' Set AppClass.App = Application
'End If
If AppClass.App Is Nothing Then
'MsgBox "found it"
Set AppClass.App = Application
End If
End Sub
When I just used:
If AppClass Is Nothing Then
...
End If
I did not trap the problem, I seemed to have to use:
If AppClass.App Is Nothing
to trap the <falling over>
Any explanation of this would be welcome.
The help is much appreciated
Tim
"Peter T" <peter_t@discussions> wrote in message
news:(E-Mail Removed)...
> Hi Tim,
>
> I understood from the onset that you are trapping application level
events,
> so you would have a class module named [say] ClassName, in the class
module
> something like this
>
> Public withevents App as Excel.application
>
> also, at module level in a normal module you would maintain a reference to
> your class named [say] ClassName
>
> Dim AppClass as ClassName
>
> In my sample code. not knowing what you named your class I wrote at random
> 'ClassName'. You will need to change this to whatever you named your
class,
> perhaps it's still named 'Class1'.
>
> Regards,
> Peter T
>
>
> "Tim Childs" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi
> >
> > I could not get the code below to compile:
> > Sub Reset_EnableEvents_NEW()
> > If AppClass Is Nothing Then
> > Set AppClass = New ClassName
> > Set AppClass.App = Application
> > End If
> > End Sub
> >
> > "New ClassName" above produced the compile error:
> > "User-defined type not defined"
> >
> > I had Option Explicit turned on in the module
> >
> > Any help welcome. THANKS
> >
> > Tim
> >
> >
> > "Tim Childs" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Hi Peter
> > >
> > > Many thanks for response
> > >
> > > I will try to assimilate in the programming. The underlying problem is
> > that
> > > sometimes the program simply does not start up properly when the file
> > > containing it is opened. The problem is intermittent so I was very
> > > interested in being able to test as directly as possible, rather than
by
> > > proxy e.g. the proxy would be testing the value of a new boolean flag
> > > variable, although I will incorporate that as well.
> > >
> > > Best wishes
> > > Tim
> > >
> > >
> > > "Peter T" <peter_t@discussions> wrote in message
> > > news:(E-Mail Removed)...
> > > > If AppClass is Nothing then ...
> > > >
> > > > If your previously created class, that holds the ref to Excel
> > > (AppClass.App
> > > > = Application) and handles application 'withevents', has
unexpectedly
> > > become
> > > > nothing, ie it's been destroyed, you can go on to recreate or
'reset'
> > it.
> > > >
> > > > You could of course use RBS's suggestion to check 'If Not bWBOpened
> > > then...'
> > > > anywhere in your code and go on to reset your objects, and perhaps
any
> > > other
> > > > global variables.
> > > >
> > > > If you are going to check your settings periodically with the OnTime
> > > method
> > > > you will need to call some routine, which might just as well be your
> > > > existing Sub Reset_EnableEvents(). But in the routine only reset if
> > > > necessary.
> > > >
> > > > Regards,
> > > > Peter T
> > > >
> > > >
|