我试图在打开工作簿时自动运行宏。我privatesub
在 ThisWorkbook 选项卡中使用该命令。
但是,当我关闭 Excel 文件并再次打开它时,宏似乎也在另一张纸上运行,导致循环引用错误。我该如何解决这个问题,使它只在一张纸上运行(“封面”)。将宏放在实际的工作表模块中会起作用吗?
Private Sub Workbook_Open()
With Sheets("Cover Sheet")
With Range("B21")
.Formula = "=COUNTIFS('Design Risk Scoring Sheet'!$AN$12:$AN$" & Sheets("Design Risk Scoring Sheet").Cells(Rows.count, "AN").End(xlUp).Row & ",""<""&B20, 'Design Risk Scoring Sheet'!$B$12:$B$" & Sheets("Design Risk Scoring Sheet").Cells(Rows.count, "AN").End(xlUp).Row & ", """" )"
.AutoFill Destination:=Range("B21:AF21"), Type:=xlFillDefault
End With
With Range("B22")
.Formula = "=COUNTIFS('Design Risk Scoring Sheet'!$BF$12:$BF$" & Sheets("Design Risk Scoring Sheet").Cells(Rows.count, "AN").End(xlUp).Row & ",""<""&B20, 'Design Risk Scoring Sheet'!$B$12:$B$" & Sheets("Design Risk Scoring Sheet").Cells(Rows.count, "AN").End(xlUp).Row & ", """" )"
.AutoFill Destination:=Range("B22:AF22"), Type:=xlFillDefault
End With
End With