I have scheduled a file to open, run macro and close after that. Everything works fine, except if I want to open the file manually, it closes on opening as it runs the macro. Is it possible to set macro to run only when file is opened automatically?
相关问题
- Excel sunburst chart: Some labels missing
- Error handling only works once
- Error handling only works once
- Excel formula in VBA code
- Excel VBA run time error 450 from referencing a ra
相关文章
- Get column data by Column name and sheet name
- programmatically excel cells to be auto fit width
- Unregister a XLL in Excel (VBA)
- Unregister a XLL in Excel (VBA)
- How to prevent excel from truncating numbers in a
- numeric up down control in vba
- Declare a Range relative to the Active Cell with V
- What's the easiest way to create an Excel tabl
Sounds like your Sub is using the Open Event. Just have it as a regualr Sub, inside a module, and use your
vbs
script to open the worksheet and run the macro.I used to do this all the time but can't find my old scripts. Found this and I know it's similar to my old ones.
Save as .vbs and schedule. Example found here . This way you can open and edit your script any time you want without it auto running.
If the time of the day you open the file yourself and the time of the day when scheduler opens it never overlap you can just add a check on current time before running the code, and if it is within the window of the scheduler to run the macro, other wise not to.
Excel can't detect if it is opened manually or by scheduler. But if you open it manually you can open it in protected view and disable macros this way. In the 'Open..' dialog click the small arrow on the 'Open' button and then select 'protected view'.