Hey Guys,
I'm having some trouble getting my script to work. What I'm trying to do is get this to open up an IE window, prompt the user to enter their username and password, and then have my script automatically fill in the username and password fields, and click submit.
I know that the submit part won't work right now, but I'm mainly concerned with the following error I keep getting:
Method 'Document' of object 'IWebBrowser2' failed
This occurs at the line that I bolded.
Can anyone see what might be wrong with this?
Thanks in Advance!
Code:
Sub OpenCIR()
Dim appIE As Object
Dim sURL As String
Dim UserN As String
Dim PW As String
Dim Element As Object
Dim btnInput As Object
Dim ElementCol As Object
Dim Link As Object
Dim strCountBody As String
Dim lStartPos As Long
Dim lEndPos As Long
Dim TextIWant As String
UserN = InputBox("Please enter your username")
PW = InputBox("Please enter your password")
Application.ScreenUpdating = False
Set appIE = CreateObject("InternetExplorer.Application")
With appIE
.Navigate "http://wsmmart.itg.ti.com/"
.Visible = True
End With
Do While appIE.Busy
Loop
Set doc = appIE.document <--- problem here
Set LoginForm = doc.forms(0)
LoginForm.getElementById("fld2").Value = UserN
LoginForm.getElementById("fld5").Value = PW
Set ElementCol = appIE.document.getElementByTagName("Submit")
For Each btnInput In ElementCol
If btnInput.Value = "Submit" Then
btnInput.Click
Exit For
End If
Next btnInput
Do While appIE.Busy
Loop
End Sub
I'm having some trouble getting my script to work. What I'm trying to do is get this to open up an IE window, prompt the user to enter their username and password, and then have my script automatically fill in the username and password fields, and click submit.
I know that the submit part won't work right now, but I'm mainly concerned with the following error I keep getting:
Method 'Document' of object 'IWebBrowser2' failed
This occurs at the line that I bolded.
Can anyone see what might be wrong with this?
Thanks in Advance!
Code:
Sub OpenCIR()
Dim appIE As Object
Dim sURL As String
Dim UserN As String
Dim PW As String
Dim Element As Object
Dim btnInput As Object
Dim ElementCol As Object
Dim Link As Object
Dim strCountBody As String
Dim lStartPos As Long
Dim lEndPos As Long
Dim TextIWant As String
UserN = InputBox("Please enter your username")
PW = InputBox("Please enter your password")
Application.ScreenUpdating = False
Set appIE = CreateObject("InternetExplorer.Application")
With appIE
.Navigate "http://wsmmart.itg.ti.com/"
.Visible = True
End With
Do While appIE.Busy
Loop
Set doc = appIE.document <--- problem here
Set LoginForm = doc.forms(0)
LoginForm.getElementById("fld2").Value = UserN
LoginForm.getElementById("fld5").Value = PW
Set ElementCol = appIE.document.getElementByTagName("Submit")
For Each btnInput In ElementCol
If btnInput.Value = "Submit" Then
btnInput.Click
Exit For
End If
Next btnInput
Do While appIE.Busy
Loop
End Sub