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

[µo°Ý] ½Ð°Ý ¦p¦ó¥Î vba ÂIÀ»ºô­¶¬d¸ß

[µo°Ý] ½Ð°Ý ¦p¦ó¥Î vba ÂIÀ»ºô­¶¬d¸ß

¥»©«³Ì«á¥Ñ GBKEE ©ó 2016-2-18 12:54 ½s¿è

ºô§}¡G http://www.twse.com.tw/ch/tradin ... T/MI_5MINS_HIST.php
<input type=button class="board" value="¬d¸ß" onclick="date_form.submit();" >
¬d¸ß¶s  µLªkÂIÀ»¡A¶]¥Xªº¸ê®Æ«D³]©wªº¬d¸ß¸ê®Æ¡A
½Ð±Ð ¦p¦ó­×§ï¤U¦Cµ{¦¡½X

Private Sub Worksheet_Change(ByVal Target As Range)

With Target
If .Row = 8 And .Column = 1 Then
    If .Value <> 10 Then
       Dim A As Object, xDate As Date, EDATE As Date
       Dim myear, mmon
       'myear = Year(Worksheets("¶×Á`").Cells(8, 1)) - 1911
       'mmon = Month(Worksheets("¶×Á`").Cells(8, 1))
    '***********´ú¸Õ¥Î
    '§ì¨ì¦³¬°¤î(¥u§ì5¤Ñ)¡A5¤Ñ³£§ì¤£¨ì¤]´£¥Ü
    Worksheets("¥[Åv«ü").Select
    EDATE = Date
    xDate = EDATE
    xDate = Worksheets("¶×Á`").Cells(8, 1)
    '*************
    'xDate = Date    '¥¿¦¡±`µ{¦¡½X
    With CreateObject("InternetExplorer.Application")
        .Visible = True
        .Navigate "http://www.twse.com.tw/ch/trading/indices/MI_5MINS_HIST/MI_5MINS_HIST.php"
        Do While .Busy Or .readyState <> 4: DoEvents: Loop
Ie_Refresh:
        With .Document
            .ALL("myear").Value = Year(xDate) - 1911 '¤é´Á¥i­×§ï
            .ALL("mmon").Value = Format(Month(xDate), "0#")
            .ALL("¬d¸ß").Click
            
           
        End With
        Do While .Busy Or .readyState <> 4: DoEvents: Loop
        If InStr(.Document.BODY.innerText, "¬dµL¸ê®Æ") Then
            If xDate >= EDATE Then   '´ú¸Õ¥Î********
            'If xDate + 4 >= Date Then   '¥¿¦¡±`µ{¦¡½X
                Debug.Print xDate       'ÅçÃҥΠ¥i§R°£
                xDate = xDate - 1
                GoTo Ie_Refresh
            End If
             .Quit
            MsgBox Format(xDate, "E/MM/DD") & " ¬dµL¸ê®Æ"
            Exit Sub
           
        End If
        Set A = .Document.GetElementsByTagName("table")
        .Document.BODY.innerHTML = A(10).outerHTML '¨ú³Ì«áªº¤@­Ó"table"
        
        Do While .Busy Or .readyState <> 4: DoEvents: Loop
        .ExecWB 17, 2       '  Select All
        .ExecWB 12, 2       '  Copy selection
        '.Quit        'Ãö³¬ºô­¶
         With ActiveSheet    '¥i«ü©w¤u§@ªí
            .UsedRange.Clear
            .Range("A1").Select
            .PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:=False, NOHTMLFormatting:=True
            Worksheets("¶×Á`").Select
        End With
           End With
    Else: .Offset(0, 1) = ""
    End If
End If
End With
End Sub

¦^´_ 1# GaryC
  1. With .Document
  2.             .all("myear").Value = Year(xDate) - 1913 '¤é´Á¥i­×§ï
  3.            MsgBox .getElementsByName("myear")(0).Value
  4.             .all("mmon").Value = Format(Month(xDate) - 1, "0#")
  5.             For Each E In .GetElementsByTagName("INPUT")
  6.                 If E.Value = "¬d¸ß" Then E.Click
  7.             Next
  8.         End With
½Æ»s¥N½X
¨C¤@­Óºô­¶(HTM )ªº«Ø¸m³£¤£¤@¼Ë.
  1. Option Explicit
  2. Sub Ex_ºô­¶¤¸¯À()
  3.     Dim i As Integer, E As Object
  4.     With CreateObject("InternetExplorer.Application")
  5.         .Visible = True
  6.         .Navigate "http://www.twse.com.tw/ch/trading/indices/MI_5MINS_HIST/MI_5MINS_HIST.php"
  7.         Do While .Busy Or .readyState <> 4: DoEvents: Loop
  8.         With .Document
  9.           '*** ³o¬qµ{¦¡½X¥i¬d¬Ý³oºô­¶ªº¤¸¯À¤º®e
  10.             On Error Resume Next
  11.             For Each E In .all
  12.                 i = i + 1
  13.                 Cells(i, "a") = E.tagname '¨Ï¥Î .GetElementsByTagName("INPUT")
  14.                 Cells(i, "b") = E.ID      '¨Ï¥Î .GetElementByID("menu")
  15.                 Cells(i, "c") = E.Name    '¨Ï¥Î .all("myear")
  16.                                           '.getElementsByName("myear")(0).Value ' = Year(xDate) - 1911
  17.                                           ' HTML ¤¤³q±`¨ã¦³¬Û¦Pªº name ÄÝ©Ê¡^¡A©Ò¦³ getElementsByName() ¤èªkªð¦^ªº¬O¤¸¯Àªº¶°¦X¡A¦Ó¤£¬O³æ¤@­Ó¤¸¯À¡C
  18.                 Cells(i, "d") = E.Value
  19.                 Cells(i, "e") = E.innertext
  20.                 Cells(i, "f") = E.Type
  21.                 Cells(i, "g") = E.href
  22.             Next
  23.         End With
  24.     '    .Quit        'Ãö³¬ºô­¶
  25.     End With
  26. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 2# GBKEE


    ¦hÁ¤j¤j¡A ¤×¨ä¨ºÀË´ú¤¸¯À ¯S§O¦³¥Î¡A ÁÂÁ ¡I

TOP

        ÀR«ä¦Û¦b : ¦³¤ß´N¦³ºÖ¡A¦³Ä@´N¦³¤O¡A¦Û³yºÖ¥Ð¡A¦Û±oºÖ½t¡C
ªð¦^¦Cªí ¤W¤@¥DÃD