Projekt-Anfragen: Tel: 07022/9319004 info@CodeDocu.de Software Entwicklung in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

Download:

Datei 1: Demo_Lock_Unlock.xlsm

Excel Code: Lock und Unlock über Buttons

 

Optischer Wechselbutton

 

Als Code und Download Beispieldatei

Excel 365

 

 

 

Option Explicit

 

 

'----< Globale Variablen >----

Public Lock_State_IsOpen As Boolean    '*bool Init=false

 

Public Const ButtonName_Admin_Locked As String = "Button_Admin_Locked"

Public Const ButtonName_Admin_UnLocked As String = "Button_Admin_UnLocked"

'----</ Globale Variablen >----

 

 

 

Public Function Lock_Set_Locked_To_ON() As Boolean

    '--------< Lock_Set_Locked_To_ON() >----------

    Lock_State_IsOpen = False

    Lock_Button_To_State_byName ButtonName_Admin_Locked, False

    Lock_Button_To_State_byName ButtonName_Admin_UnLocked, True

    '--------</ Lock_Set_Locked_To_ON() >----------

End Function

 

Public Function Lock_Set_Locked_To_OFF() As Boolean

    '--------< Lock_Set_Locked_To_OFF() >----------

    Lock_State_IsOpen = True

    Lock_Button_To_State_byName ButtonName_Admin_Locked, True

    Lock_Button_To_State_byName ButtonName_Admin_UnLocked, False

    '--------</ Lock_Set_Locked_To_OFF() >----------

End Function

 

 

Public Function Lock_Toggle_On_Off() As Boolean

    '*LockButton: Button_AdminLogin

    Dim wb As Workbook

    Set wb = ActiveWorkbook

   

    '< Suche LockButton >

    Dim objLockButton As Shape

    Set objLockButton = Lock_Find_Button(ButtonName_Admin_Locked)

    '</ Suche LockButton >

   

    '< Status ermitteln >

    '*anhand der Farbe

    Dim status_LockButton As Boolean

    If objLockButton.Visible = msoTrue Then

        '< set_To_Off >

        objLockButton.Visible = msoFalse

        status_LockButton = False

       

        Lock_Button_To_State_byName ButtonName_Admin_UnLocked, True

        '</ set_To_Off >

    Else

        '< set_To_On >

        objLockButton.Visible = msoFalse

        status_LockButton = True

       

        Lock_Button_To_State_byName ButtonName_Admin_UnLocked, False

        '</ set_To_On >

    End If

    '</ Status ermitteln >

   

    '< Ausgabe >

    '*aktuellen Status ausgeben

    Lock_Toggle_On_Off = status_LockButton

    '</ Ausgabe >

 

End Function

 

 

Public Function Lock_Find_Button(ByVal sButtonName As String) As Shape

    '--------< Lock_Find_Button() >----------

    '*LockButton: Button_AdminLogin

    Dim wb As Workbook

    Set wb = ActiveWorkbook

   

    '< Suche LockButton >

    Dim objLockButton As Shape

   

    Dim sheet As Worksheet

    For Each sheet In wb.Worksheets

        Dim objShape As Shape

        For Each objShape In sheet.Shapes

            If objShape.Name = sButtonName Then

                Set objLockButton = objShape

                Exit For

            End If

        Next

    Next

    '</ Suche LockButton >

   

    '< Ausgabe >

    Set Lock_Find_Button = objLockButton

    '</ Ausgabe >

    '--------</ Lock_Find_Button() >----------

End Function

 

 

Public Function Lock_Button_To_State_byName(ByVal sButtonName As String, ByVal SetState As Boolean)

    '--------< Lock_Button_To_State_byName() >----------

    Dim objButton As Shape

    Set objButton = Lock_Find_Button(sButtonName)

   

    Lock_Button_To_State objButton, SetState

    '--------</ Lock_Button_To_State_byName() >----------

End Function

 

Public Function Lock_Button_To_State(ByRef objButton As Shape, ByVal SetState As Boolean)

    '--------< Lock_Button_To_State() >----------

    objButton.Visible = SetState

    '--------</ Lock_Button_To_State() >----------

End Function

 

 

 

 

 

Mobile
»
Laufzeitfehler 1004: Die Methode VBProject für das Object _Workbook ist fehlgeschlagen
»
Excel Protect Parameter
»
Excel Code: Lock und Unlock über Buttons
»
Excel Arbeitsmappe schützen per Makro
»
Excel: Verhindern von Umbenennen von Arbeitsblättern
»
Excel vba: Gruppierung erlauben mit geschützten Blättern

.

Jobs, Projekte, Angebote für Freiberufler, Selbstständig an Info@CodeDocu.de