Croeg
05-12-2007, 10:56 AM
Hello,
With help from this forum, I've created a form that automatically enters a username and password in a secure website to pull data. Passwords need to be updated every 90 days. I created a simple form for the user to update their user name and password which writes back to the VBE. Everything works, but when the program is loaded, Excel crashes. Here's my code below.
Private Declare Function FindWindow Lib "USER32" Alias "FindWindowA" _
(ByVal ClassName As String, ByVal WindowName As String) As Long
Private Declare Function LockWindowUpdate Lib "USER32" _
(ByVal hWndLock As Long) As Long
Sub UpdatePswd()
Application.VBE.MainWindow.Visible = False
Dim VBEHwnd As Long
On Error GoTo ErrH:
Application.VBE.MainWindow.Visible = False
VBEHwnd = FindWindow("wndclass_desked_gsk", _
Application.VBE.MainWindow.Caption)
If VBEHwnd Then
LockWindowUpdate VBEHwnd
End If
' your code to write code
'-----------------------------------
Set VBCodeMod = ThisWorkbook.VBProject.VBComponents("Rings").CodeModule
With VBCodeMod
.ReplaceLine 22, "Private Const UserName As String = """ & Sheets("Sheet1").Range("I1").Value & """"
.ReplaceLine 23, "Private Const PassWord As String = """ & Sheets("Sheet1").Range("J1").Value & """"
End With
'-----------------------------------
Application.VBE.MainWindow.Visible = False
ErrH:
LockWindowUpdate 0&
End Sub
Thanks,
Creog
With help from this forum, I've created a form that automatically enters a username and password in a secure website to pull data. Passwords need to be updated every 90 days. I created a simple form for the user to update their user name and password which writes back to the VBE. Everything works, but when the program is loaded, Excel crashes. Here's my code below.
Private Declare Function FindWindow Lib "USER32" Alias "FindWindowA" _
(ByVal ClassName As String, ByVal WindowName As String) As Long
Private Declare Function LockWindowUpdate Lib "USER32" _
(ByVal hWndLock As Long) As Long
Sub UpdatePswd()
Application.VBE.MainWindow.Visible = False
Dim VBEHwnd As Long
On Error GoTo ErrH:
Application.VBE.MainWindow.Visible = False
VBEHwnd = FindWindow("wndclass_desked_gsk", _
Application.VBE.MainWindow.Caption)
If VBEHwnd Then
LockWindowUpdate VBEHwnd
End If
' your code to write code
'-----------------------------------
Set VBCodeMod = ThisWorkbook.VBProject.VBComponents("Rings").CodeModule
With VBCodeMod
.ReplaceLine 22, "Private Const UserName As String = """ & Sheets("Sheet1").Range("I1").Value & """"
.ReplaceLine 23, "Private Const PassWord As String = """ & Sheets("Sheet1").Range("J1").Value & """"
End With
'-----------------------------------
Application.VBE.MainWindow.Visible = False
ErrH:
LockWindowUpdate 0&
End Sub
Thanks,
Creog