简体   繁体   中英

Run a macro only if it has not been run before?

I am creating an Excel file in which there is a list of cells with descriptions for various items, and each cell has a hyperlink. I need to e-mail this to a colleague who may or may not have any experience or time for VBA, so I have written a macro that will reset the hyperlinks.

Is there a way to run the macro at the start of the file only if it has not been opened before?

I'd create a hidden page where you can store 'state' variables. On that sheet you can store if the person has run the macro before or not. So in cell A1 you can have a number 0, which will indicate the number of times the macro has been run. Update that number each time it is run. Just be sure to manually reset that sheet before sending it to the person. Also make sure that person does not send the sheet to other people who have to have it run a certain way the first time.

Why not just run your macro to reset links on the Workbook_Before_Save event, before you send it. Anything else presumes he will have macro security set and will enable the macro to run anyway, which he may not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM