[英]Why can I not use Private Sub Workbook_Open(ByVal Sh As Object) any workaround?
I want the code to run when workbook loads.我希望代码在工作簿加载时运行。 I am using
Private Sub Workbook_Open(ByVal Sh As Object)
, but it throws an error "Procedure error does not match description of event" - Any ideas please, as Private Sub Workbook_SheetActivate(ByVal Sh As Object)
works.我正在使用
Private Sub Workbook_Open(ByVal Sh As Object)
,但它抛出一个错误“程序错误与事件描述不匹配” - 请提供任何想法,因为Private Sub Workbook_SheetActivate(ByVal Sh As Object)
有效。
But I want code to run when workbook opens.但我希望代码在工作簿打开时运行。
I know that Private Sub Workbook_Open(ByVal Sh As Object)
is not allowed.我知道不允许使用
Private Sub Workbook_Open(ByVal Sh As Object)
。
See my comment, as previously stated by a few, you can't just change a signature of a standard Excel event handler.请参阅我的评论,正如之前一些人所说,您不能只更改标准 Excel 事件处理程序的签名。
However, you can work within that handler and get access to the worksheets within the workbook.但是,您可以在该处理程序中工作并访问工作簿中的工作表。
Private Sub Workbook_Open()
Dim objSheet As Worksheet
For Each objSheet In ThisWorkbook.Sheets
' Do something with the sheet that you're interested in.
Next
End Sub
I hope that helps.我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.