Link to home
Start Free TrialLog in
Avatar of jbzg
jbzg

asked on

excel vba macro, run only once

I have a server delivering an Excel file to the browser.  

I have included some (novice-level but adequate) macro code to set appropriate attributes on each sheet of the file, to control online display and printing.  I want the macro to run when the file is delivered to the browser, but not to run again if the user saves the document and later re-opens it.

(It's a WebFocus application; the macro comes from a template .mht document stored on the server.)

What mechanicsm can be used?  

If there is a way for the auto_open macro to delete itseft, that would do it.  Otherwise, it will have to sense whether to proceed or quite -- I would want to have the first-time-only detection encapsulated in a function, so I can readily re-use it.

SOLUTION
Avatar of nutsch
nutsch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just create a hidden protected sheet with a cell having true or false.  Or create a Name with a value initially set to false

Then on auto open check that variable if false do your run once routine and set that variable to true

Next time auto open happens after save the flag will be true so no need to run the macro

Make sense?

Dave
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tracy
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.