Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 从某些图纸上排除宏_Excel_Vba - Fatal编程技术网

Excel 从某些图纸上排除宏

Excel 从某些图纸上排除宏,excel,vba,Excel,Vba,如何从将在工作簿中运行的宏中排除这些工作表? 完成代码时遇到问题,因为我不熟悉排除工作表 到目前为止,我所拥有的: Dim sh As Worksheet If sh.Name <> "Apples" And sh.Name <> "Oranges" And ws.Name <> "Grapes" Then Dim sh As工作表 如果sh.命名为“苹果”,sh.命名为“橙子”,ws.命名为“葡萄”,那么 首先,创建一个变量,表示要排除的所有图纸的名

如何从将在工作簿中运行的宏中排除这些工作表? 完成代码时遇到问题,因为我不熟悉排除工作表

到目前为止,我所拥有的:

Dim sh As Worksheet
   If sh.Name <> "Apples" And sh.Name <> "Oranges" And ws.Name <> "Grapes" Then
Dim sh As工作表
如果sh.命名为“苹果”,sh.命名为“橙子”,ws.命名为“葡萄”,那么

首先,创建一个变量,表示要排除的所有图纸的名称:

Const excludeSheets as String = "Apples,Oranges,Grapes,David,Hector,Sheet1"
然后,您可以这样做:

If IsError(Application.Match(sh.Name, Split(excludeSheets,","))) Then
    'code will manipulate the sheets which are not found in the array
    MsgBox sh.Name & " is not excluded!"
Else:
    Msgbox sh.Name & " is excluded!"
End If
更新

考虑到您的新代码,我猜您没有分配
sh
变量

可以在循环结构中执行此操作:

Sub ShowMeTheSheets()

    Dim sh as Worksheet
    Const excludeSheets as String = "Apples,Oranges,Grapes,David,Hector,Sheet1"

    For each sh in ThisWorkbook.Worksheets  'Assigns a Worksheet Object to the sh Variable.
        If IsError(Application.Match(sh.Name, Split(excludeSheets,","))) Then
            'code will manipulate the sheets which are not found in the array
            MsgBox sh.Name & " is not excluded!"
        Else:
            Msgbox sh.Name & " is excluded!"
        End If
    Next
End Sub

David我得到一个运行时错误对象variabe或With block variable not setA运行时错误不能发生在我提供的代码中,除非您的其余代码是错误的。如果看不到代码的其余部分,我就帮不了你。如果在
If-IsError
行上出现错误,那么我猜您没有正确地将对象分配给
sh
变量。请修改您的原始问题,以包含您当前尝试执行的代码,并让我知道哪一行引发了错误。