creating VBA Code

Sanbiz94

New Member
Joined
Sep 26, 2011
Messages
29
Hello Excel Lovers! :)

I am Very new to excel vba i been trying to the hang of programming since i can work in excel with no problem. I have been asked by my company if i can create a code that will oppn Interent Explorer and capture data from one site. And i have the basic code but i need mixe it all together in order to get it working, every time i try to run it but an error message keeps popping up. Some tell me whats wrong with code and how can i fix it. PLease!!:(



Option Compare Text

Private Sub Worksheet_Change(ByVal Target As Range)
Dim appIE As Object
Dim rs As Recordset
Dim webaddress As String

Set rs = CurrentDb.OpenRecordset("Tables")
rs.MoveLast
rs.MoveFirst

DoCmd.SetWarnings False

On Error Resume Next

Set appIE = GetObject("InternetExplorer.Application")

appIE.Visible = True

Do Until rs.EOF
If IsNull(rs!orgwebsite) Then
webaddress = rs!link
appIE.navigate webaddress

Do Until appIE.ReadyState = 4
DoEvents
Loop


numTDs = appIE.Document.getelementsbytagname("td").Length
If numTDs = 77 Then
Title = appIE.Document.getelementsbytagname("td").Item(36).innertext
facility = appIE.Document.getelementsbytagname("td").Item(38).innertext
orgprofile = appIE.Document.getelementsbytagname("a").Item(31).href
orgwebsite = appIE.Document.getelementsbytagname("a").Item(33).href
mailaddress1 = appIE.Document.getelementsbytagname("td").Item(40).innertext
jobid = appIE.Document.getelementsbytagname("td").Item(43).innertext
acceptj1s = appIE.Document.getelementsbytagname("td").Item(45).innertext
loanpractice = appIE.Document.getelementsbytagname("td").Item(47).innertext
contact = appIE.Document.getelementsbytagname("td").Item(50).innertext
typeofrec = appIE.Document.getelementsbytagname("td").Item(52).innertext
phone = appIE.Document.getelementsbytagname("td").Item(53).innertext
fax = appIE.Document.getelementsbytagname("td").Item(54).innertext
searchfirm = appIE.Document.getelementsbytagname("td").Item(55).innertext
End If

If numTDs = 78 Then
Title = appIE.Document.getelementsbytagname("td").Item(36).innertext
facility = appIE.Document.getelementsbytagname("td").Item(38).innertext
orgprofile = appIE.Document.getelementsbytagname("a").Item(31).href
orgwebsite = appIE.Document.getelementsbytagname("a").Item(33).href
mailaddress1 = appIE.Document.getelementsbytagname("td").Item(40).innertext
mailaddress2 = appIE.Document.getelementsbytagname("td").Item(41).innertext
mailaddress3 = appIE.Document.getelementsbytagname("td").Item(42).innertext
jobid = appIE.Document.getelementsbytagname("td").Item(44).innertext
acceptj1s = appIE.Document.getelementsbytagname("td").Item(46).innertext
loanpractice = appIE.Document.getelementsbytagname("td").Item(48).innertext
contact = appIE.Document.getelementsbytagname("td").Item(51).innertext
typeofrec = appIE.Document.getelementsbytagname("td").Item(53).innertext
phone = appIE.Document.getelementsbytagname("td").Item(54).innertext
fax = appIE.Document.getelementsbytagname("td").Item(55).innertext
searchfirm = appIE.Document.getelementsbytagname("td").Item(56).innertext

End If

numAs = appIE.Document.getelementsbytagname("a").Length

' Do Until x > numAs
' test = appIE.Document.getelementsbytagname("a").Item(x).href
' Debug.Print x
' Debug.Print test
' x = x + 1
' Loop




Debug.Print jobid


rs.Edit
rs!title2 = Title
rs!facility = facility
rs!mailaddress1 = mailaddress1
rs!mailaddress2 = mailaddress2
rs!mailaddress3 = mailaddress3
rs!jobid = jobid
rs!acceptj1s = acceptj1s
rs!loanpractice = loanpractice
rs!contact = contact
rs!typeofrec = typeofrec
rs!phone = phone
rs!fax = fax
rs!searchfirm = searchfirm
rs!orgprofile = orgprofile
rs!orgwebsite = orgwebsite




End If

rs.MoveNext
Loop

rs.Close

Set rs = CurrentDb.OpenRecordset("tblSearch_Firms", dbOpenDynaset)

rs.MoveLast
rs.MoveFirst

DoCmd.SetWarnings False

On Error Resume Next

Do Until rs.EOF
'If IsNull(rs!contact) Then
webaddress = rs!orgprofile
appIE.navigate webaddress

Do Until appIE.ReadyState = 4
DoEvents
Loop
rs.Edit
rs!Specialties = ListDiv
rs!contact = contact
rs.Update

rs.MoveNext

Loop

DoCmd.SetWarnings True
appIE.Quit
rs.Close
Set ie = Nothing
Set rs = Nothing


End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,224,521
Messages
6,179,277
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top