PDA

View Full Version : Solved: Solution Re: Challenge



johnske
09-30-2004, 07:51 PM
Hi Guys,

Does anyone know how would I do the following procedure as a 'Change' event in a word document?

If (the VBA code has been changed and any attempt is made to run code)


Then (a message box pops up saying "This document will now be closed - open it again to run your code")


AutoSave and quit the document :bink:

Jacob Hilderbrand
09-30-2004, 08:36 PM
If the VBA Code has been changed? So people can change you're code and you want to know if that is the case??

johnske
09-30-2004, 08:45 PM
Not quite - the problem hinges on the fact that if the code is run before saving and completely quitting the application an error arises.

Need to overcome this so that if they forget this principle and try to run the code before saving and quitting, the document will take over and do this for them (i.e. save and quit) :bink:

johnske
09-30-2004, 09:04 PM
I'll re-phrase that slightly to make it clearer:

Not quite - the problem hinges on the fact that if their changes to the code are run before saving and completely quitting the application an error can arise when the doc is re-opened.

Need to overcome this so that if they forget this principle and try to run their new the code before saving and quitting, the document will take over and do this for them (i.e. save and quit)

(This appears to be a glitch by MS)

:bink:

fumei
09-30-2004, 10:31 PM
I am trying to understand this. You do not want newer code to be run without saving and quitting.

How on earth can you test anything? You test by running the new code. Are you saying that you want it so you can not test without a save?

I would not call that a glitch.

"changes to the code are run before saving and completely quitting the application an error can arise when the doc is re-opened."

The above implies:

1. that some sort of check is made to see if there ARE any changes to the code.

2. checks to see if the file is saved WITH those changes, but BEFORE they are run.

It seems there is a contrasiction in purpose. What if the changes are wrong? Do you want to make sure they are saved first?

Could you clarify a little bit more what the intention is?

johnske
09-30-2004, 11:06 PM
Hi,

Basically, you got it roght..Go to the end of the next post (Challenge!) & you'll see that a problem can arise when the code is run before saving and quitting...

So you save and quit (rightly or wrongly) open it up and test your code...Hey, you can always save it as a different name if you're not sure it'll work and want your original version to go back to.

The problem appears to be that the "changed" and "memorized" versions of the code on your computer for Word docs can (on certain occasions such as the one given) BOTH give results unless you substitute the changed version for the memorized one first.

John :bink:

TonyJollans
10-01-2004, 01:10 AM
Hi John,

I didn't get time to look at your solution, or at Howard's changes yesterday. I hope to do so this afternoon.

Meanwhile ..

Documents("YourDocument").Saved

will be True if there are no changes to either the document or the VBA code
will be False if there are changes to either, and ..

Documents("YourDocument").VBProject.Saved

will be False if the code has changed, and True if it hasn't

johnske
10-01-2004, 01:56 AM
Thanx muchly Tony,

So I'll need something like?...


If ThisDocument.VBProject.Saved=False then Application.Quit


But what's the code for - "if any macro is selected to be run" ?

John :bink:

johnske
10-01-2004, 03:55 AM
It's alright, dont matter, this'll do the trick if inserted in the first line of the problematic code.... :dunno


If ThisDocument.VBProject.Saved = False Then
MsgBox "This document will now be closed - you" & vbLf & _
"must open it again to run your new code"
Application.Quit
End If


Thanx :bink: