0

ワークブックで実行されるマクロからこれらのシートを除外するにはどうすればよいですか? シートの除外に慣れていないため、コードを完成させるのに苦労しています。

私がこれまでに持っているもの:

Dim sh As Worksheet
   If sh.Name <> "Apples" And sh.Name <> "Oranges" And ws.Name <> "Grapes" Then
4

1 に答える 1

0

まず、除外するすべてのシートの名前を表す変数を作成します。

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
于 2013-10-09T14:36:23.743 に答える