ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] µLªk¥Î¥~³¡¸ê®Æ¶×¤Jªººô¯¸¯à¥ÎVBAŪ¨ú¸ê®Æ¶Ü¡H

¥»©«³Ì«á¥Ñ GBKEE ©ó 2014-6-7 18:23 ½s¿è

¦^´_ 2# ¤p«L«È
¸Õ¸Õ¬Ý
  1. Option Explicit
  2. Const FormDLL = "FM20.DLL"
  3. Sub IE¤U¤@­¶()
  4.     Dim URL As String, A As Object, Table As Object, i As Integer, pubSrch As Object, Pages As Integer
  5.     Dim Sh As Worksheet, B As String
  6.     Set_FormDLL
  7.     Set Sh = ActiveSheet
  8.     Sh.Cells.Clear
  9.     URL = "https://eservices.customs.gov.hk/MSOS/wsrh/001s1?searchBy=A"
  10.     With CreateObject("InternetExplorer.Application")
  11.         .Visible = True     '  ¬O§_Åã¥Ü IE
  12.         .Navigate URL
  13.         Do While .ReadyState <> 4 Or .Busy
  14.             DoEvents
  15.         Loop
  16.         Set A = .Document.getElementsByTAGName("A")
  17.         For i = 0 To A.Length - 1
  18.             If A(i).innertext = "ALL" Then
  19.                 A(i).Click
  20.                 Exit For
  21.             End If
  22.         Next
  23.         Do While .ReadyState <> 4 Or .Busy
  24.             DoEvents
  25.         Loop
  26.         Do
  27.             Set A = .Document.getElementsByTAGName("TD")
  28.         Loop Until Not A Is Nothing And A.Length = 84
  29.         For i = 0 To A.Length - 1
  30.             If A(i).ID = "grid-table-pubSrch_center" Then
  31.                 Pages = Val(Replace(A(i).innertext, "Page  of ", ""))        'Á`­¶¼Æ
  32.             End If
  33.             If A(i).ID = "next_grid-table-pubSrch" Then Set pubSrch = A(i)                         '¤U¤@­¶«öÁä
  34.         Next
  35.         Set Table = .Document.getElementsByTAGName("table")
  36.         For i = 1 To Pages
  37.             If i >= 2 Then
  38.                 pubSrch.Click
  39.                 Do While .ReadyState <> 4 Or .Busy:        Loop
  40.                 Set Table = .Document.getElementsByTAGName("table")
  41.                 Do:  Loop Until B <> Table(6).outerHTML
  42.             End If
  43.             Ep Sh, Table(6).outerHTML
  44.             B = Table(6).outerHTML
  45.         Next
  46.         .Quit
  47.     End With
  48.     With Sh
  49.         .Cells.WrapText = False
  50.         Intersect(Range("b:b").SpecialCells(xlCellTypeBlanks).EntireRow, .Range("c:c").SpecialCells(xlCellTypeBlanks).EntireRow).Delete
  51.         .Cells.EntireRow.AutoFit
  52.         .Range("a1").Activate
  53.     End With
  54.     Remove_FormDLL

  55. End Sub
  56. Private Sub Set_FormDLL()   '·s¼W¤Þ¥Î Microsoft Forms 2.0 Object Library
  57.     On Error Resume Next
  58.     ThisWorkbook.VBProject.References.AddFromFile "C:\windows\system32\" & FormDLL
  59.   '  On Error GoTo 0
  60. End Sub
  61. Private Sub Remove_FormDLL() '§R°£¤Þ¥Î Microsoft Forms 2.0 Object Library
  62.     Dim D As Object
  63.     For Each D In ThisWorkbook.VBProject.References
  64.         If UCase(D.fullpath) Like "*" & FormDLL Then
  65.             ThisWorkbook.VBProject.References.Remove D
  66.         End If
  67.     Next
  68. End Sub
  69. Private Sub Ep(Sh As Worksheet, S As String)
  70.     Dim D As New DataObject, E As Shape, FormDLL As String ', Rng As Range
  71.     'DataObject ª«¥ó ¦b¶i¦æÂà´«°Ê§@®É¡A°µ¬°®æ¦¡¤Æ¤å¦r¸ê®Æªº¼È¦s°Ï°ì¡C¨ä¤]¥i¥H¼È¦s©MÀx¦s¦b DataObject ªº¤å¦r¤ù¬q¬ÛÃöªº®æ¦¡¡C
  72.     '«Å§i Dim D As New DataObject '¶·¦b¤u¨ã-> ³]©w¤Þ¥Î¶µ¥Ø¥[¤J ·s¼W¤Þ¥Î Microsoft Forms 2.0 Object Library ,±M®× ¥[¤J¤@ªí³æ§Y¥i
  73.     With D
  74.         .SetText S
  75.         .PutInClipboard
  76.         With Sh
  77.              .Cells(.Rows.Count, "b").End(xlUp).Offset(1, -1).Select
  78.             .PasteSpecial Format:="Unicode ¤å¦r"
  79.         End With
  80.     End With
  81. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

  1. Sub GetData()


  2. URL = "https://eservices.customs.gov.hk/MSOS/wsrh/001s1?searchBy=A"

  3. With CreateObject("InternetExplorer.Application")
  4.   .Visible = True     '  ¬O§_Åã¥Ü IE
  5.   .Navigate URL

  6. Do While .ReadyState <> 4 Or .Busy

  7. DoEvents

  8. Loop

  9. xlHtm = .Document.body.innerHTML
  10. End With

  11. End Sub
½Æ»s¥N½X
§Ú¸Õ¤F¥ÎCREATEOBJECT¡A¦ý¦³¨Ç¸ê®Æ¦h¹L¤@­¶®É¡A½Ð°Ý¦p¦óÂà­¶¡H

TOP

        ÀR«ä¦Û¦b : ¡i®É¶¡¦¨´N¤@¤Á¡j®É¶¡¥i¥H³y´N¤H®æ¡A¥i¥H¦¨´N¨Æ·~¡A¤]¥i¥HÀx¿n¥\¼w¡C
ªð¦^¦Cªí ¤W¤@¥DÃD