Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Excel Code: Lock und Unlock über Buttons

07.06.2019 (πŸ‘533)


Optischer Wechselbutton

Als Code und Download Beispieldatei

Excel 365, vba Makro

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