excel - 工作表上的 VBA excel 事件为每个工作表打开全局
问题描述
如何为每个 wokrsheet 触发 onworksheetopen 事件?我需要知道活动工作表的索引号,但是在每个工作表中编写 worksheet_open 事件有点愚蠢。我想在 Workbook 中创建全局函数(Sub)以在每次打开任何工作表时触发事件以获取它的索引号
Sub WorksheetIndex()
Dim table As String
Select Case ActiveSheet.Index
Case 4
table = "Trees"
Case 5
table = "Helps"
Case 6
table = "Plants"
Case 7
table = "Excavation"
Case 8
table = "Building"
Case 9
table = "Exterier"
Case 10
table = "Jobs"
Case 11
table = "Irrigation"
Case 12
table = "Instalation"
Case 13
table = "Systems"
Case 14
table = "Electronic"
Case 15
table = "Works"
Case 16
table = "Example"
Case 17
table = "Cars"
End Select
End If
End Sub
解决方案
Event
将此代码复制到ThisWorkbook
代码模块中,请:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
MsgBox Sh.Name & " - " & Sh.Index
'You can use it as you need and eliminate the annoying message...
End Sub
推荐阅读
- c - 如何在c中拆分字符串
- javascript - 使用 JS 槽 HTML 显示 Json
- wordpress - 覆盖 WooCommerce 过滤器中最低和最高价格的标准请求处理,以从自定义字段按价格获取产品
- java - 我的 Java 客户端没有读取整个 Socket 响应
- sapui5 - sapUI5 应用程序中的 Cloudinary SDK
- vb.net - How to Automatically Select a ListBox Item Based on the Current Month (VB.NET)
- c - 链接 .o 对象时,Makfile 会同时生成 `(.text+0x0): multiple definition` 和 `(.text+0x44): undefined reference to` 错误
- javascript - 无法在实时服务器上运行 Reactjs 代码
- java - 如何用另一个 java 对象的值更新一个 java 对象的所有字段?
- powershell - 如何在 powershell Pro Tools 中为 LogonName 组合 FirstName 和 LastName?