Har du set hvor smart det kan være?

Microsoft Office, Word skabeloner, Excel regnearkSmart Office Word skabelon system

SmartOffice - ProtectUnprotect

How to protect and unprotect sheets and workbooks using VBA.



Eksempel 1

Public Sub SheetProtectAll()
'Flemming Vadet, April 1999, fv@smartoffice.dk
    Dim wks As Worksheet
    For Each wks In ActiveWorkbook.Worksheets
        wks.Protect Password:="Tralala", DrawingObjects:=True, _
            Contents:=True, Scenarios:=True
    Next wks
    Set wks = Nothing
End Sub

Public Sub SheetUnprotectAll()
'Flemming Vadet, April 1999, fv@smartoffice.dk
    Dim wks As Worksheet
    For Each wks In ActiveWorkbook.Worksheets
        wks.Unprotect Password:="Tralala"
    Next wks
    Set wks = Nothing
End Sub

Public Sub Sheetprotect(sSheetName As String)
'Flemming Vadet, April 1999, fv@smartoffice.dk
    Dim wks As Worksheet
    Set wks = Worksheets(sSheetName)
    wks.Protect Password:="Tralala", DrawingObjects:=True, _
        Contents:=True, Scenarios:=True
    Set wks = Nothing
End Sub

Public Sub SheetUnprotect(sSheetName As String)
'Flemming Vadet, April 1999, fv@smartoffice.dk
    Dim wks As Worksheet
    Set wks = Worksheets(sSheetName)
    wks.Unprotect Password:="Tralala"
    Set wks = Nothing
End Sub
Eksempel 2

Public Sub ActiveWorkbookProtect()
    'Flemming Dahl, April 1999, fd@smartoffice.dk
    ActiveWorkbook.Protect Password:="Tralala", Structure:=True, _
        Windows:=False
End Sub

Public Sub ActiveWorkbookUnprotect()
    'Flemming Dahl, April 1999, fd@smartoffice.dk
    ActiveWorkbook.Unprotect Password:="Tralala"
End Sub

Public Sub WorkbookProtect(sBookName As String)
    'Flemming Dahl, April 1999, fd@smartoffice.dk
    Workbooks(sBookName).Protect Password:="Tralala", Structure:=True, _
        Windows:=False
End Sub

Public Sub WorkbookUnprotect(sBookName As String)
    'Flemming Dahl, April 1999, fd@smartoffice.dk
    Workbooks(sBookName).Unprotect Password:="Tralala"
End Sub
Enjoy *SS*



Download eksempel

   

Smart Office Freeware Smart Data Management
Compare 2 Columns
Excel Super- Subscript
Teachers Excel Tools
         
Smart Office - Word og Excel specialist