问题
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
Which Portland Runner has already mentioned in his post.
Private Sub Workbook_Open()
Use
Sub Auto_Open()
in a module. While we are at it, you may also want to check THIS. The link is aboutConfigure 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:
- security settings
- 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