Option Explicit
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Private Declare Function SetWindowsHookEx Lib "user32" _
Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, _
ByVal dwThreadId As Long) As Long
Private lgHook As Long
Private Declare Function GetClassName Lib "user32" _
Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" _
(ByVal hHook As Long) As Long
Function PasswordInputBox(message As String, title As String) As String
Const WH_CBT As Long = &H5
Const GWL_HINSTANCE As Long = -6
Dim lgInst As Long
PasswordInputBox = ""
lgInst = GetWindowLong(GetActiveWindow(), GWL_HINSTANCE)
#If VBA6 Then
lgHook = SetWindowsHookEx(WH_CBT, AddressOf PassWord_InputBox_Simple, _
lgInst, GetCurrentThreadId)
#Else
lgHook = SetWindowsHookEx(WH_CBT, AddrOf("PassWord_InputBox_Simple"), _
lgInst, GetCurrentThreadId)
#End If
PasswordInputBox = InputBox(message, title)
End Function
Private Function PassWord_InputBox_Simple(ByVal lMsg As Long, _
ByVal wParam As Long, _
ByRef lParam As Long) As Long
Const HCBT_CREATEWND = 3
Const GWL_STYLE = (-16)
Const ES_PASSWORD = &H20
Dim ClassName As String, RetVal As Long
If lMsg = HCBT_CREATEWND Then
ClassName = String$(128, Chr$(0))
RetVal = GetClassName(wParam, ClassName, Len(ClassName))
If Left(ClassName, RetVal) = "Edit" Then
SetWindowLong wParam, GWL_STYLE, GetWindowLong(wParam, _
GWL_STYLE) Or ES_PASSWORD
UnhookWindowsHookEx lgHook
End If
PassWord_InputBox_Simple = False
End If
End Function