online 1
gast (50)

/ Forum / Tabellenkalkulation

TabellenkalkulationTabellenkalkulation

Fragevon little-key vom 17.04.2022, 11:25 Options

Lösung

Blattschutz alle Blätter außer 2

Hallo an alle,

habe eine Tabelle mit 54 Arbeitsblättern.
Diese heißen KW1, KW2 ... bis KW52 und AR, AW.

Um alle Blätter gleichzeitig einen Blattschutz zu aktivieren, habe ich folgenden Code:

' Blattschutz für alle Blätter einschalten
Sub Blattschutz_alleBlätter_ein()
For Each WsTabelle In Sheets
WsTabelle.Protect ("sambuco")
Next WsTabelle
End Sub

der auch funktioniert.

Wie kann ich diesen Blattschutz nur auf die Blätter KW1 bis KW52 beschränken, da die Blätter AR+AW ein anderes Passwort erhalten sollen?

Danke schonmal.

Gruß Mario


Antwort schreiben

Antwort 1 von Hajo_Zi vom 17.04.2022, 11:28 Options

Hallo Mario,

If ucase( Left(wstabelle.name,2))="KW" Then WsTabelle.Protect ("sambuco")

Gruß Hajo

Antwort 2 von little-key vom 17.04.2022, 11:52 Options

Hallo Hajo,

Danke, aber irgendetwas mache ich falsch.
Bekomme diese Meldung:

Objektvariable oder With-Blockvoriable nicht festgelegt.

Kannst Du das mal in meinen vorhandenen Code einfügen?

Bin auch noch nicht so firm in VBA.
Mario

Antwort 3 von Hajo_Zi vom 17.04.2022, 12:01 OptionsLösung

Lösung
Hallo mario,

ich bekomme keinen Fehler.

Option Explicit

' Blattschutz für alle Blätter einschalten
Sub Blattschutz_alleBlätter_ein()
    Dim WsTabelle As Worksheet
    For Each WsTabelle In Sheets
        If UCase(Left(WsTabelle.Name, 2)) = "KW" Then WsTabelle.Protect ("sambuco")
    Next WsTabelle
End Sub


Gruß Hajo

Antwort 4 von little-key vom 17.04.2022, 12:15 Options

Hallo Hajo,

wiedermal besten Dank dafür. Echt Klasse.

Jetzt auf einmal funktionierts. Hatte es eigentlich genauso gemacht.
Aber warscheinlich nur "eigentlich".

Alles Gute
Mario

Antwort 5 von Hajo_Zi vom 17.04.2022, 12:18 Options

Hallo Mario,

ich habe die Variable Definiert., ist notwendig bei Option Explicit.

Gruß Hajo

Ähnliche Themen

Makro trotz Blattschutz
Musby  27.01.2009 - 39 Hits - 3 Antworten

Exel Blattschutz aufheben
buddybuddy  06.01.2009 - 307 Hits - 11 Antworten

Blätter zentrieren beim Sprung auf Textmarke
Patri_ck  04.02.2010 - 165 Hits - 4 Antworten

Excel 2007, Seitenlayout für alle Blätter
tomsan  19.02.2010 - 313 Hits - 2 Antworten

Blattschutz
Jumpanino  09.03.2010 - 231 Hits - 2 Antworten

Hinweis

Diese Frage ist schon etwas älter, Sie können daher nicht mehr auf sie antworten. Sollte Ihre Frage noch nicht gelöst sein, stellen Sie einfach eine neue Frage im Forum..

Neue Einträge

Version: supportware 1.9.150 / 10.06.2022, Startzeit:Mon Jan 26 11:26:25 2026