Forum Discussion

alex kramer's avatar
alex kramer
Copper Contributor
Jan 04, 2018

Need to edit a VBA script that automatically closes Excel

I have an Excel XLSM that is invoked by Windows Task Scheduler at a specific time each week. It updates a worksheet, saves a report (using "save as PDF"), closes the workbook and then exits Excel. How can I get to the code to edit it? Since the macro closes Excel automatically as soon as I open the workbook?

Thanks - Any suggestion is appreciated...

All on a single desktop in Windows 10

Excel - Office 365

 

4 Replies

  • Holding a Shift key down while opening a workbook will prevent any Workbook_Open or Auto_Open procedures from running.

  • Haytham Amairah's avatar
    Haytham Amairah
    Silver Contributor

    Alex,

     

    You have to disable that macro somehow to be able to open that Excel file and get access to the macro code.

     

    To do that, open a blank Excel workbook, then go to File >> Options >> Trust Center >> Trust Center Settings >> Macro Settings , or press Alt+T+M+S respectively.

    Then make sure that the option (Disable all macros with notification) is selected.

    In the same Trust Center dialog box select Trusted Documents, and click Clear button.

     

    After that, find that Excel file and open it (Do not enable macros if you are prompted to do so), then press Alt+F11 to open the VBA editor, find the macro code and edit it as you want.

    • alex kramer's avatar
      alex kramer
      Copper Contributor

      Thank You!

      Now I can insert some logic to allow me to pause and edit under certain circumstances, or execute and exit under other circumstances.  

Resources