ACommandLineKindaGuy
Active Member
- Joined
- May 11, 2002
- Messages
- 378
- Office Version
- 365
- Platform
- Windows
The following code hides the Name Box next to the formula bar and prevents users from accessing a named range and modifying it.
I would like to convert this so it runs on 64 bit Excel. Please don't suggest workarounds like "Hide the formula bar" or "protect your named ranges"
Can anyone help?
TIA John
VBA Code:
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function IsWindowEnabled Lib "user32" (ByVal hwnd As Long) As Long
Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long
Sub NameBox(TF) 'True = display it; False = hide it
'Called from:
' Workbook_Activate - False
' Workbook_Deactivate - True
' Workbook_BeforeClose - True
Dim hwndXl As Long 'Child window that contains combobox
Dim xlMain As Long 'Xl Window handle
Dim hwndcbo As Long 'Handle of NameBox dropdown
Dim wasenabled As Long 'Status of NameBox
Dim retval As Long 'return value
'Get main window, child, and NameBox handles
xlMain = FindWindowA(strXLClass, vbNullString)
hwndXl = FindWindowEx(xlMain, 0, strXLChildClass, vbNullString)
hwndcbo = FindWindowEx(hwndXl, 0, strDropBtnClass, vbNullString)
'Determine if the NameBox is currently enabled or not.
wasenabled = IsWindowEnabled(hwndcbo)
'If NameBox is hidden then display it
If wasenabled = 0 And TF Then retval = EnableWindow(hwndcbo, 1)
'If NameBox is displayed then hide it
If wasenabled = 1 And Not TF Then retval = EnableWindow(hwndcbo, 0)
End Sub
I would like to convert this so it runs on 64 bit Excel. Please don't suggest workarounds like "Hide the formula bar" or "protect your named ranges"
Can anyone help?
TIA John