Consulting

Results 1 to 9 of 9

Thread: Solved: Solution Re: Challenge

  1. #1
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location

    Solved: Solution Re: Challenge

    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

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    If the VBA Code has been changed? So people can change you're code and you want to know if that is the case??

  3. #3
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    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)

  4. #4
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    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)


  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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?

  6. #6
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    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

  7. #7
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  8. #8
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Thanx muchly Tony,

    So I'll need something like?...

    [VBA]
    If ThisDocument.VBProject.Saved=False then Application.Quit
    [/VBA]

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

    John

  9. #9
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    It's alright, dont matter, this'll do the trick if inserted in the first line of the problematic code....

    [VBA]
    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
    [/VBA]

    Thanx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •