Application Events

B

Bart Hernalsteen

Hi,

I'm trying to implement application event procedures.
I've inserted a class module etc like decribed on the
www.mvps.org/word/faqs/MacrosVBA/appClassEvenstContent.htm website.

It works fine until I end a macro by the "End" statement. Why ?

I added a watch for my oAppClass object
It exist until I run the "End" statement, then its reporting "object
variable or with block variablel not set"
I work with Word Xp on a Win Xp prof. station.

Any suggestions ?

Thanks

Bart Hernalsteen
 
M

mksmith

Why are you using an 'End' statement? There is no real reason to use
this statement and when you get to writing compiled code, i.e. VB, the End
statement causes no end of problems.

Basically, don't use it to stop execution. Let the code run out of scope.

Malc
www.dragondrop.com
 
K

Klaus Linke

I think you could use "Exit Sub" instead. There was an endless (sic) thread
about "End" in one of the VBA groups last year...

Klaus
 
M

mksmith

I'm not going to even bother looking as I still remember it! :)

The only thing that I am amazed at is that it took so many messages; I
could imagine three messages should have done it.

Person A. Should I use 'End' in my code?
Person B. No. Never.
Person C. We all agree...

Malc
www.dragondrop.com
 
C

Cindy Meister -WordMVP-

Indeed, one could. But I prefer one entry and one exit point in each
routine - after all there may be some cleaning up to do.
At the risk of starting another "ENDless" thread...

Most error-handling code I've seen (outside of NET) requires an Exit Sub
before the error handling lines (so that the error handling isn't
executed). Do you use a different approach, then?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
M

Malcolm Smith

Cindy

What I do is to have the exit block before the error block and then the
error block either Resumes Next or Resume to the Exit block.


Something like:


Sub CindyProc()

On Error Goto Error_CindyProc

' Lots of code


Exit_CindyProc

On Error Resume Next
' My clean-up code
Exit Sub

Error_CindyProc:

If Err.Number = NOTASERIOUSERROR then
Resume Next
Else
LogError Err, "CindyProc"

Resume Exit_CindyProc
End If
End Sub



The log file would also include the line:

MsgBox "Error:" & Str$(ErrNumber) & " - " & ErrDescription,
vbOkOnly+vbExclamation, "Error:: " & sRoutine



That's how I do it. I think it's one of the better possibilities given
the tools available within VB/VBA.

Regards
Malc
www.drgondrop.com
 
C

Cindy Meister -WordMVP-

Hi Malcolm,
What I do is to have the exit block before the error block and then the
error block either Resumes Next or Resume to the Exit block.
OK, then you DO use Exit Sub (that's what I wasn't sure about - that you
actually have it in your code). You just make sure you use it only ONCE -
I'm with you, then :)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top