spurs
Active Member
- Joined
- Oct 18, 2006
- Messages
- 479
- Office Version
- 2016
- 2013
- 2010
- 2007
- 2003 or older
- Platform
- Windows
Several years ago this forum assisted me with the following code which will type an asterisk in place of the letter typed in order to hide your password from sight as you type it on screen
It works fine as long as Excel is running in 32 bit mode. Some users who open up my workbooks are in 64 bit mode now and they get errors .
Is there a different way to code this that is compatible both in 32 and 64 bit formats for excel?
Option Explicit
''/////////////////////////////////////////////////////////////////
''// Password hiding routine downloaded from internet
''// http://www.xcelfiles.com/API_09.html
''/////////////////////////////////////////////////////////////////
Public Declare Function GetActiveWindow Lib "user32" () As Long
Public 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
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Private Const nIDE As Long = &H100
Private Const EM_SETPASSWORDCHAR = &HCC
Private hdlEditBox As Long
Private Fgrndhdl As Long
Public Function TimerFunc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal nEvent As Long, ByVal nSecs As Long) As Long
Dim hdlwndAct As Long
'// Do we have a handle to the EditBox
If hdlEditBox > 0 Then Exit Function
'// Get the handle to the ActiveWindow
hdlwndAct = GetActiveWindow()
'// Get the Editbox handle
hdlEditBox = FindWindowEx(hdlwndAct, 0, "Edit", "")
'// Set the password character for the InputBox
SendMessage hdlEditBox, EM_SETPASSWORDCHAR, Asc("*"), ByVal 0
End Function
Public Function InPutBoxPwd(fPrompt As String, Optional fTitle As String, Optional fDefault As String, _
Optional fXpos As Long, Optional fYpos As Long, Optional fHelpfile As String, Optional fContext As Long) As String
Dim sInput As String
'// Initialize
hdlEditBox = 0
Fgrndhdl = GetForegroundWindow
'// Windows-Timer
SetTimer Fgrndhdl, nIDE, 100, AddressOf TimerFunc
'// Main InputBox
If fXpos Then
sInput = InputBox(fPrompt, fTitle, fDefault, fXpos, fYpos, fHelpfile, fContext)
Else
sInput = InputBox(fPrompt, fTitle, fDefault, , , fHelpfile, fContext)
End If
'// Kill the correct Timer
KillTimer Fgrndhdl, nIDE
'// Pass result
InPutBoxPwd = sInput
End Function
It works fine as long as Excel is running in 32 bit mode. Some users who open up my workbooks are in 64 bit mode now and they get errors .
Is there a different way to code this that is compatible both in 32 and 64 bit formats for excel?
Option Explicit
''/////////////////////////////////////////////////////////////////
''// Password hiding routine downloaded from internet
''// http://www.xcelfiles.com/API_09.html
''/////////////////////////////////////////////////////////////////
Public Declare Function GetActiveWindow Lib "user32" () As Long
Public 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
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Private Const nIDE As Long = &H100
Private Const EM_SETPASSWORDCHAR = &HCC
Private hdlEditBox As Long
Private Fgrndhdl As Long
Public Function TimerFunc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal nEvent As Long, ByVal nSecs As Long) As Long
Dim hdlwndAct As Long
'// Do we have a handle to the EditBox
If hdlEditBox > 0 Then Exit Function
'// Get the handle to the ActiveWindow
hdlwndAct = GetActiveWindow()
'// Get the Editbox handle
hdlEditBox = FindWindowEx(hdlwndAct, 0, "Edit", "")
'// Set the password character for the InputBox
SendMessage hdlEditBox, EM_SETPASSWORDCHAR, Asc("*"), ByVal 0
End Function
Public Function InPutBoxPwd(fPrompt As String, Optional fTitle As String, Optional fDefault As String, _
Optional fXpos As Long, Optional fYpos As Long, Optional fHelpfile As String, Optional fContext As Long) As String
Dim sInput As String
'// Initialize
hdlEditBox = 0
Fgrndhdl = GetForegroundWindow
'// Windows-Timer
SetTimer Fgrndhdl, nIDE, 100, AddressOf TimerFunc
'// Main InputBox
If fXpos Then
sInput = InputBox(fPrompt, fTitle, fDefault, fXpos, fYpos, fHelpfile, fContext)
Else
sInput = InputBox(fPrompt, fTitle, fDefault, , , fHelpfile, fContext)
End If
'// Kill the correct Timer
KillTimer Fgrndhdl, nIDE
'// Pass result
InPutBoxPwd = sInput
End Function