gpt4 book ai didi

excel - 在 Excel 中重命名工作表事件

转载 作者:行者123 更新时间:2023-12-03 15:06:58 25 4
gpt4 key购买 nike

重命名 excel 工作表时让一些 VBA 代码运行的最佳方法是什么?

最佳答案

即使使用 Application 对象,显然也没有事件来处理这个问题。多么烦人。

我可能会尝试通过存储工作表的启动值并检查尽可能多的事件来捕获它——这无疑是一种黑客行为。

以下似乎对我有用,希望它有所帮助。

在 ThisWorkbook 模块中:

Private strWorksheetName As String

Private Sub Workbook_Open()
strWorksheetName = shtMySheet.Name
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Call CheckWorksheetName
End Sub
Private Sub Workbook_NewSheet(ByVal Sh As Object)
Call CheckWorksheetName
End Sub
Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Call CheckWorksheetName
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Call CheckWorksheetName
End Sub
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Call CheckWorksheetName
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Call CheckWorksheetName
End Sub

Private Sub CheckWorksheetName()
'If the worksheet has changed name'
If shtMySheet.Name <> strWorksheetName Then

DoSomething

End If
End Sub

关于excel - 在 Excel 中重命名工作表事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1939919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com