I have been trying to use an already existing open Internet Explorer page to fill a form. I am new to VBA, about a week or so, but i have been able do several things with it already. As i can open a new web page and post data into it. I think i read all post relating to this topic and have found several codes that i though would work but did not.
I have several companies that require data entry, but there website is structured in a way that after login in all sub pages shows the home URL. So i can't navigate directly. The only way i have been able to get to their forms is by coding link after links to get to the designated form that i need to complete. To work around this i though I would just open and get to the web page manually to were the form is and then run the macro at that instance to transfer data from excel to the form. I have tried changing things around, but my lack of knowledge with vba i have not been able to solve this problem.
I have tried using google search page as the test page and inserting this to see if if it post the text "test" into the search page.
If the code provided below is not a good code to use and for an existing open Internet Explorer page. Please provide example of one that works and were to start my personal coding into.
.Document.getElementsByID("q")(0).Value = "test"
In all prior codes i have viewed the two codes below seems to be the simplest, but i can't get them to work
The second one runs and test come back as if it found it when i have it open and does nothing when i have internet explorer. I have tried posting right after this test but no matter i structure my code all i get is errors. Any help is welcomed.
-------------------First Code--------------------
----> If objSW.Count Then ' new<----- I get hung up and get the following error on the first code
run time error '91':
Object variable or with Block variable not set
Public Sub CheckIE()
Dim objSW As SHDocVw.ShellWindows
Dim objIE As SHDocVw.InternetExplorer
Dim objDoc As Object
Dim bAppRunning As Boolean
'Set objSW = New SHDocVw.ShellWindows
If objSW.Count Then ' new
For Each objDoc In objSW
If InStr(1, objDoc.LocationName, "Google") Then
bAppRunning = True
objDoc.Visible = True
Exit For
End If
Next objDoc
End If
If bAppRunning = False Then
Set objIE = CreateObject("InternetExplorer.Application") ' new
objIE.Visible = True
objIE.Navigate "www.google.com"
End If
Set objIE = Nothing
Set objSW = Nothing
End Sub
Paul D
----------------------Second Code------
Set SWs = New SHDocVw.ShellWindows
For Each vIE In SWs
If Left(vIE.LocationURL, 4) = "http" Then 'avoid explorer windows/etc this way
If MsgBox("IE Window found. The URL is:" & vbCrLf & vIE.LocationURL & vbCrLf & _
vbCrLf & "Do you want to see the html?", vbYesNo) = vbYes Then
'Show html in a msgbox
MsgBox vIE.Document.body.innerHTML
'Or put it to a file
'Dim vFF As Long
'vff=freefile
'open "C:\thehtml.txt" for output as #vff
'print #vff,vie.document.body.innerhtml
'close #vff
End If
End If
Next
Set SWs = Nothing
Set vIE = Nothing
End Sub
Bookmarks