彰化一整天的論壇

 找回密碼
 立即註冊
查看: 697|回復: 0

IE (Internet Explorer) Automation using Excel VBA

[複製鏈接]
發表於 2014-11-13 13:53:36 | 顯示全部樓層 |閱讀模式
  1. Private Sub IE_Autiomation()
  2.     Dim i As Long
  3.     Dim IE As Object
  4.     Dim objElement As Object
  5.     Dim objCollection As Object

  6.     ' Create InternetExplorer Object
  7.     Set IE = CreateObject("InternetExplorer.Application")

  8.     ' You can uncoment Next line To see form results
  9.     IE.Visible = False

  10.     ' Send the form data To URL As POST binary request
  11.     IE.Navigate "http://www.excely.com/"

  12.     ' Statusbar
  13.     Application.StatusBar = "www.excely.com is loading. Please wait..."

  14.     ' Wait while IE loading...
  15.     Do While IE.Busy
  16.         Application.Wait DateAdd("s", 1, Now)
  17.     Loop

  18.     ' Find 2 input tags:
  19.     '   1. Text field
  20.     '   <input type="text" class="textfield" name="s" size="24" value="" />
  21.     '
  22.     '   2. Button
  23.     '   <input type="submit" class="button" value="" />
  24.    
  25.     Application.StatusBar = "Search form submission. Please wait..."

  26.     Set objCollection = IE.document.getElementsByTagName("input")

  27.     i = 0
  28.     While i < objCollection.Length
  29.         If objCollection(i).Name = "s" Then

  30.             ' Set text for search
  31.             objCollection(i).Value = "excel vba"

  32.         Else
  33.             If objCollection(i).Type = "submit" And _
  34.                objCollection(i).Name = "" Then

  35.                 ' "Search" button is found
  36.                 Set objElement = objCollection(i)

  37.             End If
  38.         End If
  39.         i = i + 1
  40.     Wend
  41.     objElement.Click    ' click button to search
  42.    
  43.     ' Wait while IE re-loading...
  44.     Do While IE.Busy
  45.         Application.Wait DateAdd("s", 1, Now)
  46.     Loop

  47.     ' Show IE
  48.     IE.Visible = True

  49.     ' Clean up
  50.     Set IE = Nothing
  51.     Set objElement = Nothing
  52.     Set objCollection = Nothing

  53.     Application.StatusBar = ""
  54. End Sub
複製代碼
資料來源: http://discuz.bestdaylong.com/fo ... ;tid=34881#lastpost
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

 ㄚ母滴雞湯
 員林香純滴雞精

Archiver|手機版|小黑屋|彰化一整天的論壇(Excel,Office)  |网站地图

GMT+8, 2019-9-22 14:26 , Processed in 0.139639 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表