Workbook_Open sub won't run when I open the workbook?

后端 未结 6 591
自闭症患者
自闭症患者 2020-12-11 01:07

This program is supposed to create a button that the user can press to activate a different sub. From my searches online, it seems that the sub below should activate when op

6条回答
  •  -上瘾入骨i
    2020-12-11 01:32

    My solution was kind of obscure, and I don't even remember now why it occurred to me as a potential solution. The file I created in which the Workbook_Open() macro would not run, I originally created through the following steps:

    1. Right clicked in the relevant folder, clicked New, clicked Microsoft Excel Worksheet.
    2. Named the file "Workbook_1".
    3. Opened Workbook_1.
    4. File, Save As, changed file type to Excel Macro-Enabled Workbook (*.xlsm), Save.
    5. Wrote VBA code including a Workbook_Open() nested in ThisWorkbook.

    For whatever reason, I wondered if my problem had anything to do with the fact that the file "started as" a standard .xlsx. So I simply:

    1. Opened a new blank Workbook within Excel (Book1).
    2. File, Save As, input Workbook_2, changed filed type to Excel Macro-Enabled Workbook (*.xlsm), Save.
    3. Copied VBA code and structure from the original Workbook_1.

    Unlike the original Workbook_1, the new Workbook_2 successfully ran the Workbook_Open() sub on open. Maybe a potential cause of this problem is related to the file's type history (i.e. if it was at some point a type that cannot run macros). Or maybe simply trying again with a new file is what solved this problem for me. Either way, this may work for anyone for which other solutions did not.

提交回复
热议问题