castertroy
New Member
- Joined
- Mar 6, 2010
- Messages
- 32
I have a code that works fine to take control of an IE window and complete a form. For some reason it isn't working for a specific webpage and is giving the dreaded runtime error 91. Here is the code:
I can't figure out why it works for other websites but not this one. Here is the HTML code for the field I am trying to populate.
Can anyone think of a reason why an error is being generated? This code is tried and tested for 4 similar webpages and I am stumped as to why this one should be different.
Code:
Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 09/03/2011 by X'
Dim Shell As Object
Dim IE As Object
Dim oForm As Object
Dim objShellWins As SHDocVw.ShellWindows
Dim objIE As SHDocVw.InternetExplorer
Dim objDoc As Object
Dim usdURL As String
Dim myUSD As String
Dim ws As Worksheet
Dim UserNameInputBox As HTMLInputElement
Dim IeApp As Object
Set ws = Worksheets("Sheet1")
Set Shell = CreateObject("Shell.Application")
For Each IE In Shell.Windows
If IE.LocationURL = "mywebpage" Then
IE.Visible = True
SetForegroundWindow IE.hwnd
Set srch = IE.document.getElementById("strLOGON")
Set rng = Range("='Sheet1'!A1")
srch.Value = rng
End If
Next
'
End Sub
I can't figure out why it works for other websites but not this one. Here is the HTML code for the field I am trying to populate.
Code:
<td align="right" class="normal">Please enter UserID  <input type="text" onkeypress="return entsub(this.form)" maxlength="16" name="strLOGON" value="" /></td>
</tr>
Can anyone think of a reason why an error is being generated? This code is tried and tested for 4 similar webpages and I am stumped as to why this one should be different.