How to tell if macro has been executed

J

JonSteng

I have a series of macros that offers the user options to run all or only
part of the macros. It opens with a form that has check boxes with three
selections (Insert Table of Contents, add Frame and add Page Border) and the
user can select all or only one, etc.

The program runs fine the first time through, but if it is run again it can
get messy if options already run are chosen again.

Is there a way that I can check to see if a selection has been executed,
even if the document has been closed and re-opened?

Thank you.
 
C

Chuck Henrich

You could set a flag in the document when each option is chosen and executed.
Your code would first test for the existence/value of your flag and then
proceed based on what it found, and setting an appropriate flag when it is
done (successful or not).

Three types of flags come to mind (all explained in VBE help):

custom document properties - good if you want to be able to modify the flag
manually as well as by code but not usable if the document is protected in
any way

document variables - good if you don't want users to mess with the flag or
accidentally delete it (as they might with a bookmark), also good if the
document is protected, but not manipulable by hand (only by code)

bookmarks - good if you need to be able to find and work with
ranges/selections

Which one you use depends on what you want to do.

HTH
 
J

JonSteng

Thank you very much - after posting my question I researched some more and
started to work with the custom document properties, but your suggestion for
the document variables seems much cleaner and safer. After just a bit of
testing it will work out to do exactly what I need.

Thanks again,

Jon
 

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