hatman
Well-known Member
- Joined
- Apr 8, 2005
- Messages
- 2,664
After exhausting all avenues to get direct access to our vaulted drawing database, I have been told that the only access that anyone needs is through the online Search Engine. They just don't want to acknowledge that anyone might want to automate the process. That leaves me with the option of letting people do this manually or automating a session of Explorer to perform all of the navigations.
Trying to automate IE...
I got most of it to work, until I added the curve ball of "What if the user is not logged into the system already?" The answer is that IE gets directed to a login screen. So I figured out how to detect that possibility. I built a userform that gets the login info, and populates the fields in the IE Form. I figured out how to Click the Submit Button.
What I can't figure out is how to handle the Security Alert dialog that pops up. It's a standard internet security warning dialog telling the user thet they are about to send secure information that could be hijacked, blah, blah, blah. This window does not seem to be the active IE window... in fact I don't think it is an IEFrame class, so I can't manipulate it with the IE object in my code. Sendkeys won't work because by this point the active window is Excel again (becaus eof the userform that popped up). So I fell back on SendMEssage() from the WinAPI. I figure I can either send the "Enter" key or the "Y" key, but niether seems to work.
I'm stumped. Here is my code up to the SendMessage call... HELP!
Trying to automate IE...
I got most of it to work, until I added the curve ball of "What if the user is not logged into the system already?" The answer is that IE gets directed to a login screen. So I figured out how to detect that possibility. I built a userform that gets the login info, and populates the fields in the IE Form. I figured out how to Click the Submit Button.
What I can't figure out is how to handle the Security Alert dialog that pops up. It's a standard internet security warning dialog telling the user thet they are about to send secure information that could be hijacked, blah, blah, blah. This window does not seem to be the active IE window... in fact I don't think it is an IEFrame class, so I can't manipulate it with the IE object in my code. Sendkeys won't work because by this point the active window is Excel again (becaus eof the userform that popped up). So I fell back on SendMEssage() from the WinAPI. I figure I can either send the "Enter" key or the "Y" key, but niether seems to work.
I'm stumped. Here is my code up to the SendMessage call... HELP!
Code:
Global flag As Boolean
Private Const VK_RETURN = &HD
Private Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Sub Doc_Search()
'reference: Microsoft Internet Controls
'reference: Microsoft HTML Object Library
Dim mIE As InternetExplorer
Dim Item_link As HTMLLinkElement
Dim Item_form As HTMLFormElement
Dim doc As HTMLDocument
Set mIE = New InternetExplorer
mIE.Visible = True
mIE.Navigate "http://none of your business"
Do Until mIE.readyState = READYSTATE_COMPLETE
Loop
Set doc = mIE.Document
For Each Item_form In doc.forms
If Item_form.Name = "login" Then
UserForm1.Show
If flag Then
Set doc = Nothing
mIE.Quit
Set mIE = Nothing
Exit Sub
End If
For Each Item In Item_form
If Item.Name = "USER" Then
Item.Value = UserForm1.TextBox1.Value
ElseIf Item.Name = "PASSWORD" Then
Item.Value = UserForm1.TextBox2.Value
ElseIf Item.Name = "login" Then
Item.Click
Exit For
End If
Next Item
a = mIE.hwnd
b = FindWindow(vbNullString, "Security Alert")
SendMessage b, VK_RETURN, 0, 0