Link to home
Start Free TrialLog in
Avatar of WarLord
WarLord

asked on

HTML

Hello,

Does anybody knows how to let A VB programm fill in text boxes that are in a web page?

so that when i let my programm open www.google.com and i have a textbox in my programm and when i fill some stuff in the textbox my programm pasts the text from the textbox in the textbox from google

Greets Erik
Avatar of DocM
DocM

Here is an example with Hotmail.

'Make a reference to Microsoft Internet Controls
Dim WithEvents IE As InternetExplorer
Private Sub Form_Load()
Set IE = New InternetExplorer
With IE
     .navigate "www.hotmail.com"
     .Visible = True
End With
End Sub
 
Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
 
If (pDisp Is IE) Then
    If InStr(1, URL, "passport.com/cgi-bin/login", vbTextCompare) Then
            Dim inp As Object
            Set inp = IE.document.All.Item("login")
            inp.Value = "username"  'replace with your id
           
            Set inp = IE.document.All.Item("passwd")
            inp.Value = "password"  'replace with your password
           
            Set inp = IE.document.All.Item("enter")
            inp.Click
     End If
End If
End Sub
 
Avatar of WarLord

ASKER

ok but what about when i don't want it to open in an external internet explorer like it happens here
Use WebBrowser control in your Form and pass the same arguments stated above into your WebBrowser control
Avatar of WarLord

ASKER

can anyone help me with this?

when i try this

Dim WithEvents IE As InternetExplorer
Private Sub Command1_Click()
Set IE = New InternetExplorer
With IE
    .Navigate "www.google.com"
    .Visible = True
End With
End Sub
Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
           Dim inp As Object
                         
           Set inp = IE.Document.All.Item("q")
           inp.Value = "Test"
           
           Set inp = IE.Document.All.Item("btng")
           inp.Click
             
   
End Sub


it does everything it should do... fill in test at the textbox in the google form press the submit button etc

but when it's loaded it gives an error 438 object doesn't support this property... i think because the program reloads the page every time ( why? ) and in the second form of google the search field isn't called Q  

ASKER CERTIFIED SOLUTION
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or:

if (pdisp is IE) then
  if instr(1,url,"what you need goes here", vbtextcompare) then
         IE.Document.All.Item("q").Value = "Test"
         IE.Document.All.Item("btng").Click
  end if
end if
 
End Sub

or (faster):
Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)

if (pdisp is IE) then
 if instr(1,url,"what you need goes here", vbtextcompare) then
        with IE.Document.All
             .Item("q").Value = "Test"
             .Item("btng").Click
        end with
 end if
end if
 
End Sub
Optionally, you could use Google API stuff.
http://www.google.com/apis/
Avatar of WarLord

ASKER

Ok this stuff works all GREAT just what i needed, one more thing remaining... let's say i have a page my programm fills some stuff presses a button then it goes to the next page... how can i let my programm fill in stuff on the next page?
Avatar of WarLord

ASKER

not only this answer but the rest of your asnwers are also very helpfull
Checking the url is the basic way:

if instr(1,URL,"Partial_and_unique_string_of_target_url_goes_here",vbtextcompare) then
    'do something
end if

if instr(1,URL,"Partial_and_unique_string_of_next_target_url_goes_here",vbtextcompare) then
    'do something more
end if

and so on...