controling Internet Explorer from Excel...

N

nisgore

I'm trying to develop a macro that will let me log onto a website and
allow me to check several boxes on a form then submit it... having lots
of problems trying to figure out how to do simple things like set the
name into the username textbox, submit, or check checkboxes because I
can't really access the internet explorer objects... anyone know how to
do this????? Here's what I have so far... any help is much
appreciated, thanks.

references must be set to Microsoft Internet Controls
***********************************************************************
Sub Macro1()

Dim IExp As Object

Set IExp = CreateObject("InternetExplorer.Application")

IExp.Visible = True
IExp.navigate "http://www.salesgenie.com/"

IExp.Quit

End Sub
********************************************************************
 
G

GysdeJongh

Hi,
I found a trick. I display an Internet explorer from VBA , because it is not
easy to get a handle in an existing IE. Then I display a userform with the only
purpose that the process will wait there till the userform is handeled.In the
meantime you can use the IE to logon to your site and do all things you want to.
Then you click the OK button of the userform and the process will resume.At this
point you can capture the data from the IE window. With the mshtml object you
can manipilate the DOM and extract data.A global varaible is used for
communication.

So you have 1 module and 1 Userform with 1 OK and 1 cancel Button
Before you start the routine resize every thing on your desktop
so that you can see : Excel , the userform and the IE

this is the Module :
======================================================
' sAnsw is the global variable used for communication
'If Cancel sAnsw = "STOP" ;terminate
Public sAnsw As String
Sub SearchInWeb()
'
'Gys Jul-2003
'
'Use an instance of the internet explorer to gather
'information from a website
'
Dim mySheet As Worksheet
Dim myIE As InternetExplorer
Dim myPage As HTMLDocument
'sBuffer string which holds the HTML
Dim sBuffer As String
'Sec Time to wait in seconds.Used to prevent hammering
Dim Sec As Single
'
'
Sec = 5
'
'Capture the active sheet.This sheet will
'contain the input and the output from the site
Set mySheet = ActiveSheet
Set myIE = New InternetExplorer
myIE.Visible = True
myIE.navigate url:="http://www.yourURL"
'
'Wait till the browser has arrived at the URL
Do
DoEvents
Loop While myIE.readyState <> 4
Call NoHammer(Sec)
'
UserForm1.Show
'
'Sub SearchInWeb will wait here till the UserForm is
'handeled and hidden.In the meantime the browser
'can be navigated.Thereafter the Go or cancel button
'can be used.Each button will hide the UserForm so
'Sub SearchInWeb will resume action
If sAnsw = "STOP" Then
Exit Sub
End If
'
'
'At this place insert the code for retrieving data from you webpage
'for instance by capturing all the text in the oage a buffer :
'
'
sBuffer = myPage.body.innerHTML
'
'
Sub NoHammer(Time As Single)
'
'This routine inserts a waiting time before the
'next request at the URL is made
Dim T1 As Variant
Dim T2 As Variant
T1 = Now
Do
DoEvents
T2 = Now
Loop While (T2 - T1) * 24 * 60 * 60 < Time
End Sub
===============================================
the code in the Userform :
===============================================
Private Sub CommandButton1_Click()
sAnsw = "GO"
'Only after hiding the UserForm Sub Suckit will resume
UserForm1.Hide
End Sub

Private Sub CommandButton2_Click()
sAnsw = "STOP"
'Only after hiding the UserForm Sub Suckit will resume
UserForm1.Hide
End Sub
==============================================

hth
Gys
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top