what is a good way to autorun macros upon open

左心房为你撑大大i 提交于 2019-12-06 04:56:15

问题


I've tried using the code that many sites have suggested to autorun a list of macros upon opening an Excel workbook. Attached is my VBA code on ThisWorkbook:

Private Sub WorkbookOpen()


MsgBox "STOP!  Do NOT attempt to highlight any fields manually!" & vbCrLf & _
     "Any highlighting will be overwritten upon reentry of this workbook.", vbOKOnly     +vbExclamation

Call Melanoma.ReformatDeplete
Call Melanoma.CScheckNO
Call Melanoma.CScheckMissing
Call Glioma.ReformatDeplete
Call Glioma.ReformatGBM
Call Glioma.CScheckNO
Call Glioma.CScheckMissing
Call Breast.ReformatDeplete
Call Breast.CScheckNO
Call Breast.CScheckMissing
Call Lymphoma.ReformatDeplete
Call Lymphoma.CScheckNO
Call Lymphoma.CScheckMissing
Call Lung.ReformatDeplete
Call Lung.CScheckNO
Call Lung.CScheckMissing
Call Miscellaneous.ReformatDeplete
Call Miscellaneous.CScheckNO
Call Miscellaneous.CScheckMissing
Call Normals.ReformatDeplete
Call Normals.CScheckNO
Call Normals.CScheckMissing


End Sub

Obviously, I saved the workbook as a 2010 macro-enabled workbook, but when I open the workbook, nothing happens on its on, I still have to click the "run button" in VBA

Any suggestions?

Thanks!


回答1:


You are close, just add the underscore

Private Sub Workbook_Open()



回答2:


There are two main ways to run the macro on workbook open

  1. Which Portland Runner has already mentioned in his post. Private Sub Workbook_Open()

  2. Use Sub Auto_Open() in a module. While we are at it, you may also want to check THIS. The link is about Configure a macro to run automatically upon opening a workbook

Private Sub Workbook_Open() is better than Sub Auto_Open() because of many reasons as mentioned in that link.




回答3:


There are two possible reasons the macro will not run automatically:

  1. security settings
  2. the macro is not located in the workbook code area


来源:https://stackoverflow.com/questions/19406979/what-is-a-good-way-to-autorun-macros-upon-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!