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

[µo°Ý] CreateObject("InternetExplorer.Application") °õ¦æ§¹¦³®É·|µLªk¸õ¥X??

¦^´_ 1# t8899

ªí®æ¤¤«ö¤U·Æ¹«¥kÁä

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

TOP

¦^´_ 3# t8899
  1. Option Explicit
  2. Sub TWSE_¥æ©ö¸ê°T()
  3.     Dim YMD_day As String, N As Name, webURL As String
  4.     YMD_day = InputBox("¿é¤J ¥Á°ê¦~«× : 102/10/07", "¤U¸ü¯S©w¤é´Áªº¸ê®Æ", Format(Date - 1, "E/MM/DD")) '¥Á°ê¦~«× "102/10/07"
  5.     With ActiveSheet  '¥i«ü©w¤u§@ªí
  6.         '·í¤é¨R¾P¥æ©ö¼Ðªº¤Î²Î­p
  7.         webURL = "URL;http://www.twse.com.tw/ch/trading/exchange/TWTB4U/TWTB4U.php?input_date=" & YMD_day & "&login_btn=¬d¸ß.dat"
  8.         '¹dÃB¥æ©ö¤é¦¨¥æ¸ê°T
  9.         'webURL = "URL; http://www.twse.com.tw/ch/trading/block/BFIAUU/BFIAUU.php?input_date=" & YMD_day & "&login_btn=¬d¸ß.dat"
  10.         'webURL = "URL; http://www.twse.com.tw/ch/trading/block/BFIAUU/BFIAUU.php?input_date=" & YMD_day & "&login_btn=%ACd%B8%DF.dat"
  11.         If .QueryTables.Count = 0 Then
  12.             .QueryTables.Add Connection:=webURL, Destination:=.Range("A1")
  13.         Else
  14.             .QueryTables(1).Connection = webURL
  15.         End If
  16.         .Cells.Clear
  17.         With .QueryTables(1)
  18.             .WebSelectionType = xlSpecifiedTables
  19.             .WebFormatting = xlWebFormattingNone
  20.            ' .WebTables = "data_table"  '¹dÃB¥æ©ö¤é¦¨¥æ¸ê°T     :¸ê®Æ¶×¤JªºTables
  21.             .WebTables = "9,11"         '·í¤é¨R¾P¥æ©ö¼Ðªº¤Î²Î­p :¸ê®Æ¶×¤JªºTables
  22.             .Refresh BackgroundQuery:=False
  23.         End With
  24.     End With
  25. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 8# t8899
  1. Option Explicit
  2. Sub ¶°¤¤¥«³õ¤j½L¸ê°T()
  3.     Dim x, ie As Object, Sh As Worksheet
  4.     Set ie = CreateObject("InternetExplorer.Application")
  5.    ' ie.Visible = True          '¬O§_Åã¥Ü IE
  6.     ie.Navigate "about:Tabs"    'ªÅ¥Õªººô­¶
  7.     Set Sh = ActiveSheet        '³]©w¤u§@ªí
  8.     Sh.Cells.Clear
  9.     Application.ScreenUpdating = False
  10.     With CreateObject("InternetExplorer.Application")
  11.     '    .Visible = True        '¬O§_Åã¥Ü IE
  12.         .Navigate "http://newmis.twse.com.tw/stock/group.jsp?ex=tse&ind=TIDX#STATISTICS"
  13.         Do While .readyState <> 4
  14.             DoEvents
  15.         Loop
  16.         For Each x In .document.getElementsByTagName("table")
  17.             If x.ID <> "logo" Then
  18.                 With ie
  19.                     .document.body.innerHTML = x.outerHTML
  20.                     Do While .readyState <> 4 Or .busy
  21.                         DoEvents
  22.                     Loop
  23.                     .execwb 17, 2       '  ºô­¶¤å¦r Select All
  24.                     .execwb 12, 2       '  ºô­¶¤å¦r Copy
  25.                     With Sh
  26.                         If .UsedRange.Rows.Count = 1 Then
  27.                             .Range("A1").Select
  28.                         Else
  29.                             .Range("A" & .UsedRange.Rows.Count + 1).Select
  30.                         End If
  31.                         .PasteSpecial Format:="HTML"
  32.                     End With
  33.                 End With
  34.             End If
  35.         Next
  36.         .Quit
  37.     End With
  38.     ie.Quit
  39.     With Sh
  40.         .Columns.WrapText = False
  41.         .Columns.AutoFit
  42.         .[a1].Select
  43.     End With
  44.     Application.ScreenUpdating = True
  45. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 2# t8899
¦¹ºô­¶ªºµ{¦¡½X
  1. Option Explicit
  2. Sub timestock()
  3. Application.ScreenUpdating = False
  4.     Dim i As Integer, S As Integer, K As Integer, j As Integer
  5.     Dim Element
  6.     With CreateObject("InternetExplorer.Application")
  7.         '.Visible = True           '¥iÅã¥Üºô­¶
  8.        .Navigate "http://newmis.twse.com.tw/stock/group.jsp?ex=tse&ind=TIDX#STATISTICS"
  9.         Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
  10.         Set Element = .document.getelementsbytagname("table")
  11.         With Sheets("SHEET5")
  12.            .Cells.Clear
  13.             'For s = 0 To element.Length - 1 '¤£ª¾¦¹ºô­¶ªºtable¤º®e:½Ð¥ý¦æ´ú¸Õºô­¶ªº§¹¾ãtable¤º®e
  14.             For S = 1 To 3                    '¤w§ä¥Xºô­¶ªºtable¤º®e¦b 0-3 ¤¤
  15.                 For i = 0 To Element(S).Rows.Length - 1
  16.                     K = K + 1
  17.                  For j = 0 To Element(S).Rows(i).Cells.Length - 1   '¸ê®ÆªºÄæ¦ì¦@6¦ì
  18.                          .Cells(K, j + 1) = Element(S).Rows(i).Cells(j).innerText
  19.                     Next
  20.                Next
  21.             Next
  22.      '       .Cells.EntireColumn.AutoFit            '¦Û°Ê½Õ¾ãÄæ¼e
  23.       '      .Cells.EntireRow.AutoFit               '¦Û°Ê½Õ¾ã¦C°ª
  24.         End With
  25.        .Quit
  26.     End With
  27.     Set Element = Nothing
  28.     MsgBox "0K"
  29. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2014-1-14 13:57 ½s¿è

¦^´_ 15# t8899
¤@ª½¥X²{"ok"°T®§µøµ¡??  §A¬O¤¤¾Ç¥ÍÀ³¸Ó·|Ãö³¬³o"ok"µøµ¡.¦³°ÝÃD¸ÕµÛ¦Û¤v¸Ñ¨M,VBA¤~·|¶i¨B.
ªþ¤WÀɮ׬ݬÝ
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 18# t8899
³o¤è¦V¬O¹ïªº,¦³¶i¨B

  1. For S = 2 To 3                    '§ä¥Xºô­¶ªºtable ¤º®e¦b 0-3 ¤¤
  2.   'j=2
  3. IF S=2 Then j=?                '¼g¤U§Aªº±ø¥ó
  4. IF S=3 Then j=?
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2014-1-15 19:33 ½s¿è

¦^´_ 21# t8899
ThisWorkbook µ{¦¡½X
  1. Option Explicit
  2. Dim Ie As Object, Msg As Boolean
  3. Private Sub Workbook_BeforeClose(Cancel As Boolean)
  4.     Ie.Quit
  5. End Sub
  6. Private Sub Workbook_Open()
  7.     Set Ie = CreateObject("InternetExplorer.Application")
  8.     Ie.Navigate "http://newmis.twse.com.tw/stock/group.jsp?ex=tse&ind=TIDX#STATISTICS"
  9.     Do While Ie.Busy Or Ie.ReadyState <> 4: DoEvents: Loop
  10.     Msg = False
  11.     timestock
  12. End Sub
  13. Private Sub timestock()
  14.     Dim i As Integer, S As Integer, K As Integer, j As Integer
  15.     Dim Element
  16.     If Msg = True Then Ie.Quit:   End
  17.     Application.OnTime Time + #12:00:30 AM#, "ThisWorkbook.timestock"
  18.     Application.ScreenUpdating = False
  19.     Do While Ie.Busy Or Ie.ReadyState <> 4: DoEvents: Loop
  20.     Set Element = Ie.document.getelementsbytagname("table")
  21.     With Sheets("sheet5")
  22.         .Cells.Clear
  23.         For S = 2 To 3                    '¤w§ä¥Xºô­¶ªºtable¤º®e¦b 0-3 ¤¤
  24.             For i = 0 To Element(S).Rows.Length - 1
  25.                 K = K + 1
  26.                 For j = 0 To Element(S).Rows(i).Cells.Length - 1   '¸ê®ÆªºÄæ¦ì¦@6¦ì
  27.                     .Cells(K, j + 1) = Element(S).Rows(i).Cells(j).innerText
  28.                 Next
  29.             Next
  30.         Next
  31.      '       .Cells.EntireColumn.AutoFit            '¦Û°Ê½Õ¾ãÄæ¼e
  32.       '      .Cells.EntireRow.AutoFit               '¦Û°Ê½Õ¾ã¦C°ª
  33.     End With
  34. End Sub
  35. Private Sub The_End()  '°±¤îªºµ{¦¡
  36.     Msg = True
  37. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 26# t8899
  1. Private Sub timestock()
  2.     Dim i As Integer, S As Integer, K As Integer, j As Integer
  3.     Dim Element
  4.     'timestock³oµ{§Ç¤ºªºDim«Å§i ¬O¬°timestock³oµ{§Çªº¨p¥ÎÅܼÆ
  5.     'timestock³oµ{§Ç°õ¦æ§¹²¦©Ò¦³ªº¨p¥ÎÅܼƷ|¦Û°ÊÄÀ©ñ
  6.     'µL¶· Set Element = Nothing
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

        ÀR«ä¦Û¦b : ¡i®É¤é²öªÅ¹L¡j¤@­Ó¤H¦b¥@¶¡°µ¤F¦h¤Ö¨Æ¡A´Nµ¥©ó¹Ø©R¦³¦hªø¡C¦]¦¹¥²¶·»P®É¶¡Ävª§¡A¤Á²ö¨Ï®É¤éªÅ¹L¡C
ªð¦^¦Cªí ¤W¤@¥DÃD