Вы находитесь на странице: 1из 6

Sub OpenPage() Dim ie As InternetExplorer Set ie = New InternetExplorer ie.Navigate "http://www.google.com.br" ie.Document.getElementsByName("q").Item.InnerText = "Pesquisa" ie.Document.getElementById("mytext1").Item.Value = "Valor" ie.Document.all.Item("btnG").Click ie.Document.getElementsByName("btnG").Item.

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

Checking a Value in a CheckBox:


<input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br /> <input type="checkbox" name="vehicle" value="Car" /> I have a car<br /> Sub OpenPage() Dim ie As InternetExplorer Set ie = New InternetExplorer ie.Navigate "http://users5.nofeehost.com/BackOfficeSite/" ie.Visible = True ie.Document.All.Item("vehicle")(1).Checked = True ie.Document.All.Item("vehicle").Item(1).Checked = True ie.Document.getElementsByName("vehicle")(1).Checked = True End Sub

Checking a value in a Radio Button:


Sub OpenPage() Dim ie As InternetExplorer Set ie = New InternetExplorer ie.Navigate "http://users5.nofeehost.com/BackOfficeSite/" ie.Visible = True ie.Document.All.Item("sex").Item(1).Checked = True End Sub

RadionButton and CheckBox we use the following code:


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("sex") If obj.Value = "female" Then obj.Checked = True End If Next obj 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

End Sub Reading data from Tables :


<table> <tr> <td>Cell 1 row 1</td> <td>Cell 2 row 1</td> <td>Cell 3 row 1</td> </tr> <tr> <td>Cell 1 row 2</td> <td>Cell 2 row 2</td> <td>Cell 3 row 2</td> </tr> </table>

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

Dealing with Frames :


<frameset cols="25%,75%"> <frame src="http://users5.nofeehost.com/BackOfficeSite/Frame_A.html"name ="Frame_A"></frame> <frame src="http://users5.nofeehost.com/BackOfficeSite/Vba_Site_Iv_Table s.htm"name="Frame_B"></frame> </frameset>

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

Вам также может понравиться