ªð¦^¦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

¦^´_ 5# ¤p«L«È
1) "FM20.DLL" ¬OMicrosoft Forms 2.0 Object Library ¡A¦ý¦pªG§Ú·Q¤F¸Ñ¥¦ªº¥\¯à©M¨Ï¥Î¤è«K¡AÀ³¸Ó¦p¦ó¤J¤â¡H
Private Sub Ep(Sh As Worksheet, S As String)
  Dim D As New DataObject ,VBA¤¤­n¤Þ¥Î¶µ¥ØMicrosoft Forms 2.0 Object Library
¬¡­¶Ã¯ ¤¤¥u­n¦³¨Ï¥Î¨ì MSFormsªº±±¨î¶µ VBA³£·|¦Û°Ê¦a¤Þ¥ÎMicrosoft Forms 2.0 Object Library

2) "grid-table-pubSrch_center"¡B"next_grid-table-pubSrch"¡A³o¨Çkeyword¬O¦p¦ó§ä¥X¨Ó¡H§Ú¦b­ì©lÀɧ䤣¨ì......
½Ð°Ñ¦Ò Private Sub ºô­¶ªº¤¸¯À()

3) §Ú¹ïCreateObject("InternetExplorer.Application")ªº¾Þ§@¤£¤F¸Ñ¡A¦³¨S¦³¬ÛÃö¸ê®Æ¥i¥H°Ñ¦Ò¡H
Google CreateObject("InternetExplorer.Application") ¬Ý¬Ý
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2014-6-14 20:44 ½s¿è

¦^´_ 7# ¤p«L«È
§âºô­¶¤Wªº¸ê®Æ·í¦¨FORM¨ÓŪ¨ú


Ex.rar (2.21 KB)


ÀɮפU¸ü«á,¦p¹Ï¥Ü¶×¤J ªí³æ



·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 9# ¤p«L«È
  1. Do
  2.             Set A = .Document.getElementsByTAGName("TD")
  3.         Loop Until Not A Is Nothing And A.Length = 84
  4.         MsgBox A.Length  '¥i¬Ý¬Ý­Ë©³¬O¦h¤Ö
½Æ»s¥N½X
Set A = .Document.getElementsByTAGName("TD")
¤£©ñ¦b Do   Loop °j°é¤]¥i¥H,
¦ý¦]ºô­¶¸ê®Æ¤U¸ü³t«×¤ñµ{¦¡³t«×°õ¦æºC,¾É­P  A Is Nothing
¥u±o¥Î  Do   Loop  ª½¨ì Not A Is Nothing
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

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

¦^´_ 11# ¤p«L«È
  1. 'ºô­¶·j´Mµ²ªG: 0 °O¿ý
  2. Option Explicit
  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, E
  6.     Set Sh = ActiveSheet
  7.     Sh.Cells.Clear
  8.     '************************************
  9.     url = "https://eservices.customs.gov.hk/MSOS/wsrh/001s1?"  
  10.    'url = "https://eservices.customs.gov.hk/MSOS/wsrh/001s1?"searchBy=A"  'ºô­¶¦³¸ê®Æ
  11.     '************************************
  12.     With CreateObject("InternetExplorer.Application")
  13.         .Visible = True     '  ¬O§_Åã¥Ü IE
  14.         .Navigate url
  15.         Do While .ReadyState <> 4 Or .Busy
  16.             DoEvents
  17.         Loop
  18.         Do
  19.             Set a = .Document.getElementsByTAGName("TD")
  20.         Loop Until Not a Is Nothing 'And a.Length = 84
  21.         On Error Resume Next
  22.         With Sh
  23.             For i = 0 To a.Length - 1
  24.                 .Cells(i + 1, "A") = i
  25.                 .Cells(i + 1, "B") = a(i).Type
  26.                 .Cells(i + 1, "C") = a(i).ID
  27.                 .Cells(i + 1, "D") = a(i).InnerText
  28.                 .Cells(i + 1, "E") = a(i).Value
  29.             Next
  30.             
  31.         End With
  32.         
  33.         .Quit
  34.     End With
  35.     MsgBox "getElementsByTAGName(""TD"") ¦X­p " & a.Length
  36. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

        ÀR«ä¦Û¦b : ºÉ¦h¤Ö¥»¥÷¡A´N±o¦h¤Ö¥»¨Æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD