gpt4 book ai didi

vba - 检查项目是否在 ParamArray VBA 中

转载 作者:行者123 更新时间:2023-12-03 01:00:58 27 4
gpt4 key购买 nike

我正在编写一个函数来在工作簿的所有工作表上运行一些宏,排除的工作表列表除外。我将排除工作表的列表作为 ParamArray 传递,但在对照 ParamArray 中的列表检查当前工作表时遇到问题。

Public Sub RunThingsOnSheets(ParamArray excludedSheets())

Dim ws as Worksheet
For Each ws In ActiveWorkbook.Worksheets
If ws Not In excludedSheets Then 'In Pseudocode this is what I want
"do things"
End If
Next ws

End Sub

Public Sub Test()

Call RunThingsOnSheets(SheetOne, SheetTwo)

End Sub

最佳答案

Public Sub RunThingsOnSheets(ParamArray excludedSheets())
Dim ws As Worksheet, o, inList As Boolean

For Each ws In ActiveWorkbook.Worksheets
inList = False
For Each o In excludedSheets
If o.Name = ws.Name Then
inList = True
Exit For
End If
Next
If Not inList Then
Debug.Print "not in excludedsheets: " & ws.Name
End If
Next ws

End Sub

Public Sub Test()

RunThingsOnSheets Sheet1, Sheet3

End Sub

关于vba - 检查项目是否在 ParamArray VBA 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29687322/

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