Here is my solution using purely VBA. Thanks @PEH for his great detailed answer w/ many alternatives.
All you'd need to do is call SetMinMaxEnabledInExcelStatusBar
module somehow.
Note: You could totally skip the SetRegKey
and just SaveRegKey
each run, I'm not sure which method I like better. I mostly used the SetRegkey
as my testing module and then left it alone once it worked and I'm of the mindset why mess w/ registry if the "RegKeyCurrentStateInt = RegKeyDesiredStateInt"
Public Const DWordRegKeyEnabled As Integer = 1
Public Const DWordRegKeyDisabled As Integer = 0
Public RegKeyStr As String, RegKeyLocStr As String, RegKeyNameStr As String
Public RegKeyDesiredStateInt As Integer, RegKeyCurrentStateInt As Integer
Public RegKeyFoundBool As Boolean
Public Sub SetMinMaxEnabledInExcelStatusBar()
RegKeyDesiredStateInt = DWordRegKeyEnabled
RegKeyLocStr = "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\" & Application.Version & "\Excel\StatusBar\"
RegKeyNameStr = "MaxValue"
RegKeyStr = RegKeyLocStr & RegKeyNameStr
Debug.Print "RegKeyStr = " & RegKeyStr
Call SetRegKey(RegKeyStr, RegKeyDesiredStateInt)
RegKeyNameStr = "MinValue"
RegKeyStr = RegKeyLocStr & RegKeyNameStr
Debug.Print "RegKeyStr = " & RegKeyStr
Call SetRegKey(RegKeyStr, RegKeyDesiredStateInt)
End Sub
Public Sub SetRegKey(RegKeyStr As String, RegKeyDesiredStateInt As Integer)
RegKeyFoundBool = RegKeyExists(RegKeyStr)
Debug.Print "RegKeyFoundBool = " & RegKeyFoundBool
If RegKeyFoundBool = False Then
Debug.Print "RegKeyFoundBool = False"
Call SaveRegKey(RegKeyStr, RegKeyDesiredStateInt)
Else
Debug.Print "RegKeyFoundBool = True"
RegKeyCurrentStateInt = ReadRegKeyVal(RegKeyStr)
Debug.Print "RegKeyCurrentStateInt = " & RegKeyCurrentStateInt
If RegKeyCurrentStateInt <> RegKeyDesiredStateInt Then
Debug.Print "RegKeyCurrentStateInt <> RegKeyDesiredStateInt"
Call SaveRegKey(RegKeyStr, RegKeyDesiredStateInt)
Else
Debug.Print "RegKeyCurrentStateInt = RegKeyDesiredStateInt"
End If
End If
End Sub
Public Function ReadRegKeyVal(RegKeyStr As String) As Integer
ReadRegKeyVal = CreateObject("WScript.Shell").RegRead(RegKeyStr)
End Function
Public Function RegKeyExists(RegKeyStr As String) As Boolean
On Error GoTo ErrorHandler
CreateObject("WScript.Shell").RegRead (RegKeyStr)
RegKeyExists = True
Exit Function
ErrorHandler:
RegKeyExists = False
End Function
Public Sub SaveRegKey(RegKeyStr As String, RegKeyDesiredStateInt As Integer, Optional RegKeyType As String = "REG_DWORD")
CreateObject("WScript.Shell").RegWrite RegKeyStr, RegKeyDesiredStateInt, RegKeyType
Debug.Print "Generated --> " & RegKeyStr & "," & RegKeyDesiredStateInt & "," & RegKeyType
End Sub