Ich bin ein VBA-Neuling versucht herauszufinden, wie eine Reihe von Arbeitsmappen und ihre Blätter durchlaufen, um ein bestimmtes Blatt zu finden, aber einige Probleme mit meinen Objektvariablen haben .Verwenden von für jede durch eine Reihe von Arbeitsmappen durchlaufen
Unten ist der Code, den ich "geschrieben" habe (zusammengeklebt könnte eine passendere Beschreibung sein). Ich habe verschiedene Korrekturen ausprobiert, aber nur scheinbar das Problem von einem Ort zum anderen verschieben. Jede Hilfe wird geschätzt!
Sub NestedForEach()
'Create an object variable to represent each worksheet
Dim WS As Worksheet
Dim WB As Workbook
Set WB = ActiveWorkbook
Set WS = Workbook.Sheets
'create a boolen variable to hold the status of whether we found worksheet "D"
Dim IsFound As Boolean
'initialise the IsFound boolean variable
IsFound = False
For Each WB In Application.Workbooks
For Each WS In WB.Worksheets
If WS.Name = "d" Then
IsFound = True
Exit For
End If
Next WS
Next WB
If IsFound Then
MsgBox "sheet D has been found in " & ActiveWorkbook.Name
Else
MsgBox "we could not locate sheet D in any of the open workbooks"
End If
End Sub
Hallo Ralph, es funktioniert jetzt perfekt. Ich schätze die Zeit und Mühe! – user6189814