Created
January 27, 2022 09:54
-
-
Save HeimMatthias/31eeaa2a14ba1c5495a96db7615b10e4 to your computer and use it in GitHub Desktop.
This Excel-VBA script helps you to unlock individual cells that have already been unlocked using the 'editable ranges' method. Since Excel Online and the table versions of Excel do not support the latter method, this script will help you make your partially protected sheets functional on all platforms.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ' UnlockEditableRanges: Hebt im aktiven Dokument auf allen Blättern den individuellen Sperrschutz der Zellen auf, die durch bearbeitbare Bereiche freigegeben wurden. | |
| ' Dadurch werden diese Bereiche auch auf Excel Online und auf Tablets beschreibbar, selbst wenn das Blatt geschützt ist. | |
| ' Achtung: bereits entsperrte Zellen werden durch das Skript nicht wieder geschützt, wenn sie sich nicht (mehr) in einem bearbeitbaren Bereich befinden. | |
| Sub UnlockEditableRanges() | |
| Dim Sheet As Excel.Worksheet | |
| Dim EditableRange As Variant | |
| Dim SheetIsProtected As Boolean | |
| Dim cell As Excel.Range | |
| For Each Sheet In ActiveWorkbook.Worksheets | |
| Debug.Print "Zellschutz in Tabellenblatt " & Sheet.Name & " aufgrund von bearbeitbaren Bereichen setzen." | |
| SheetIsProtected = Sheet.ProtectContents | |
| Sheet.Protect 'Blattschutz ist notwendig, damit AllowEdit abgefragt werden kann | |
| For Each EditableRange In Sheet.Protection.AllowEditRanges | |
| Debug.Print "Bereich " & EditableRange.Title & "(" & EditableRange.Range.Address & ") wird entsperrt" | |
| For Each cell In EditableRange.Range.Cells | |
| If cell.AllowEdit Then | |
| Sheet.Unprotect | |
| If cell.MergeCells Then | |
| Debug.Print "Verbundene Zellen " & cell.MergeArea.Address & " werden entsperrt" | |
| cell.MergeArea.Locked = False | |
| Else | |
| cell.Locked = False | |
| End If | |
| Sheet.Protect | |
| End If | |
| Next | |
| Next | |
| If Not SheetIsProtected Then Sheet.Unprotect | |
| Next | |
| End Sub |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For a comparison of the two cell protection methods in Excel, see here:
https://support.microsoft.com/en-us/office/lock-or-unlock-specific-areas-of-a-protected-worksheet-75481b72-db8a-4267-8c43-042a5f2cd93a