Macro Crawler
Macro Crawler
Click ie.Visible = True End Sub Private Sub CommandButton1_Click() ' Intializing IE8 and navigate 2 SFDC LogIn site 'UserForm3.Show IE.Navigate2 "https://na7.salesforce.com/" IE.Visible = True Do DoEvents Loop Until IE.ReadyState = READYSTATE_COMPLETE Application.Wait Now + TimeValue("0:00:12") ' To Log In SFDC Set doc = IE.Document With doc .getElementById("username").innerText = TextBox1.Text .getElementById("password").innerText = TextBox2.Text End With Dim htmlColl As IHTMLElementCollection Dim htmlInput As HTMLInputElement Set htmlColl = doc.getElementsByTagName("input") Do While doc.ReadyState <> "complete": DoEvents: Loop For Each htmlInput In htmlColl If Trim(htmlInput.Type) = "submit" Then htmlInput.Click Exit For End If Next htmlInput To Access the elements which are there in forms doc.forms("editPage").Item("00NA0000000b8Zc").Value = ActiveCell.Offset(0, 3).Value2 doc.all.tags("a").Item(tagcount - 6).Click Do DoEvents Loop Until IE.ReadyState = READYSTATE_COMPLETE End Sub
Selecting a value in a ComboBox and ListBox: <select name="cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option> </select>
Sub OpenPage() Dim ie As InternetExplorer Set ie = New InternetExplorer ie.Navigate "http://users5.nofeehost.com/BackOfficeSite/" ie.Visible = True ie.Document.All.Item("cars").Item(1).Selected = True End Sub
The HTML code of a ListBox that enables multiple selected values is the following: <select name="drop1" id="Select1" size="4" multiple="multiple"> <option value="1">item 1</option> <option value="2">item 2</option> <option value="3">item 3</option> <option value="4">item 4</option> <option value="0">All</option> </select>
Sub OpenPage() Dim ie As InternetExplorer Set ie = New InternetExplorer Dim obj As Object ie.Navigate "http://users5.nofeehost.com/BackOfficeSite/" ie.Visible = True For Each obj In ie.Document.All.Item("drop1").Options If obj.innertext = "item 3" Then obj.Selected = True End If Next obj End Sub
Clicking on links:
<a href="http://www.yahoo.com/">Click Here</a>
Sub OpenPage() Dim ie As InternetExplorer Set ie = New InternetExplorer ie.Navigate "http://users5.nofeehost.com/BackOfficeSite/Vba_Site_I v_Links.htm" ie.Visible = True
If ie.Document.Links.Length > 0 Then ie.Document.Links(0).Click End If Dim obj As Object For Each obj In ie.Document.Links If obj.href = "http://www.yahoo.com/" Then obj.Click End If Next obj
Sub OpenPage() Dim ie As InternetExplorer Set ie = New InternetExplorer ie.Navigate "http://users5.nofeehost.com/BackOfficeSite/Vba_Site_Iv_Tables.htm" ie.Visible = True Dim elemCollection As Object Dim obj As Object Set elemCollection = ie.Document.getElementsByTagName("TABLE") For Each obj In elemCollection MsgBox obj.Rows(0).Cells(0).innerText Next obj End Sub Sub ReadTable() Dim ie As InternetExplorer Set ie = New InternetExplorer ie.Navigate "http://users5.nofeehost.com/BackOfficeSite/Vba_Site_Iv_Tables.htm" ie.Visible = True Dim elemCollection As Object Dim t As Integer Dim r As Integer, c As Integer Set elemCollection = ie.Document.getElementsByTagName("TABLE") For t = 0 To elemCollection.Length - 1 For r = 0 To elemCollection(t).Rows.Length - 1 For c = 0 To elemCollection(t).Rows(r).Cells.Length - 1 ThisWorkbook.Worksheets(1).Cells(r + 1, c + 1) = elemCollection(t).Rows(r).Cells(c).innerText Next c Next r Next t End Sub
Sub OpenPage() Dim ie As InternetExplorer Set ie = New InternetExplorer ie.Navigate "http://users5.nofeehost.com/BackOfficeSite/Vba_Site_I v_Frames.htm" ie.Visible = True MsgBox ie.Document.frames("Frame_A").Document.all.Item(0).innertext End Sub