Hallo,
gibt es eine Möglichkeit ein Makro (VBA) auf alle in einer Datei enthaltenen Tabellenblätter anzuwenden?
Ich möchte, dass bei öffnen der Datei das folgende Makro auf allen Tabellenblättern ausgeführt wird:
Private Sub Workbook_Open()
Cells.EntireRow.Hidden = False
Dim ob As Range
Dim rng As Range, firstAddress, temp As Range
Set rng = Columns(1) 'anpassen! falls es nur eine Spalte ist reicht Columns(1) 'für Spalte A Columns (2) für Spalte B usw.
Set ob = rng.Find("*Gesperrtes Projekt", LookIn:=xlValues)
If Not ob Is Nothing Then
firstAddress = ob.Address
Do
If temp Is Nothing Then Set temp = ob
Set temp = Application.Union(temp, ob)
Set ob = rng.FindNext(ob)
Loop While Not ob Is Nothing And ob.Address firstAddress
End If
temp.EntireRow.Hidden = True
End Sub
Hi RB,
ungetestet, probier mal dies:
Option Explicit
'
Private Sub Workbook\_Open()
Dim ob As Range, rng As Range, firstAddress, temp As Range
Dim wks As Worksheet
For Each wks In ThisWorkbook.Worksheets
With wks
.Cells.EntireRow.Hidden = False
Set rng = .Columns(1)
Set ob = rng.Find("\*Gesperrtes Projekt", LookIn:=xlValues)
If Not ob Is Nothing Then
firstAddress = ob.Address
Do
If temp Is Nothing Then Set temp = ob
Set temp = Application.Union(temp, ob)
Set ob = rng.FindNext(ob)
Loop While Not ob Is Nothing And ob.Address firstAddress
End If
End With
Next wks
temp.EntireRow.Hidden = True
End Sub
Gruß
Reinhard
Hallo Reinhard,
leider wird das Makro nicht ausgeführt und der Debugger markiert diese Zeile. Woran kann das liegen?
Set temp = Application.Union(temp, ob)
Gruß Susanne
leider wird das Makro nicht ausgeführt und der Debugger
markiert diese Zeile. Woran kann das liegen?
Set temp = Application.Union(temp, ob)
Hi Susanne,
schwierig aus der Ferne, sind temp und ob auch ein Range?
Union braucht zwei Ranges.
Bau mal Msgbox Typename(temp)
und das Gleiche für ob mit ein.
Dann vor dem Union-Aufruf noch
Msgbox temp.address
Msgbos ob.address
Union ist da sehr heikel, es kann nur zu einem schon bestehenden Range einen anderen dazufügen.
Ist eines dabei was kein Range ist (also leer o.ä.) dann knallts.
Wenns nicht weiterhilft frag weiter nach, sieht lösbar aus.
Gruß
Reinhard