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

[µo°Ý] ªÑ²¼¾ú¥v»ù®æªí

[µo°Ý] ªÑ²¼¾ú¥v»ù®æªí

¶i¤J³o­Óºô¯¸¨ú±o­ÓªÑ¾ú¥v»ù¡G
http://www.cnyes.com/twstock/ps_historyprice/2330.htm

Â^¨ú.JPG
2017-10-13 15:40

¥¦¥u¦³©T©wªº¤é´Á°Ï¶¡¸ê®Æ

½Ð±Ð¾É ¡G
              VBA ¦p¦ó¥Î ¿ï¥Î¨ä¤¤ªº"¶}©l¤é´Á"¤Î"µ²§ô¤é´Á"¤Î "¬d¸ß" ¦Ó¨ú±o§óªø°Ï¶¡ªº¸ê®Æªí

ÁÂÁÂ

¦^´_ 1# Scott090

°Ñ¦Ò¥H¤Uµ{¦¡½X¥i¥H³]©w¤é´Á°Ï¶¡
Ä~Äò´M¨D§ó¨Îªº¤èªk
  1. '±q¹d¦ëºô¨ú±o¾ú¥vªÑ»ù
  2. '¨Ï¥Î IE ª«¥ó
  3. 'option explicit
  4. 'option base 1

  5. Sub TestCNYES()

  6.     Dim Price(0 To 20, 0 To 9)
  7.     Dim Code
  8.     Code = "2330"
  9.    
  10.     Dim IE As Object, URL$
  11.     Dim date0 As Date, StartDate$, EndDate$, timer, time0 As Date
  12.     Dim Table As Object, oDoc As Object, E
  13.     Dim Re%, Ce%, i%, k%, ColName$
  14.    
  15.     ActiveSheet.Cells.Clear
  16.    
  17.     '³]©w¸ê®Æ¶}©l¤Îµ²§ô¤é´Á
  18.     StartDate = Format(DateAdd("m", -2, Date), "yyyy/mm/dd")   '¨ú2­Ó¤ëªº¸ê®Æ¡A¬ù40µ§
  19.     EndDate = Format(Date, "yyyy/mm/dd")
  20.    
  21.     k = 0
  22. Again:
  23.     Set IE = CreateObject("InternetExplorer.Application")
  24.     With IE
  25.             URL = "http://www.cnyes.com/twstock/ps_historyprice/" & Code & ".htm"
  26.             .Visible = False                '¤£Åã¥Ü IE
  27.             .navigate URL
  28.             
  29.             time0 = Now() + #12:00:05 AM#   '³]©w®É¶¡±±¨î­p®É5¬íÄÁ
  30.             Do
  31.                 DoEvents
  32.             Loop While (.Busy Or .readystate <> 4) And Time < time0
  33.            
  34.            'ºô­¶¥¼·Ç³Æ¦n¡AÃö³¬­«±Ò
  35.             If .readystate <> 4 Then
  36.                 .Quit
  37.                 k = k + 1
  38.                 If k <= 2 Then GoTo Again
  39.                 GoTo GiveUp                   '¶}±Ò3¦¸³£¥¢±Ñ´N©ñ±ó
  40.             End If
  41.             
  42.             Set oDoc = .Document.getElementsByTagName("input")
  43.             With oDoc
  44.                  .Item("ctl00$ContentPlaceHolder1$startText").Value = StartDate ' ¶}©l¤é´Á input name
  45.                  .Item("ctl00$ContentPlaceHolder1$endText").Value = EndDate     ' µ²§ô¤é´Á input name
  46.             
  47.                  Set E = .Item("ctl00$ContentPlaceHolder1$submitBut")           '¬d¸ßÁä¦WºÙ
  48.                     E.Click                                                     '«ö¬d¸ßÁä
  49.             End With
  50.             
  51.             k = 0
  52.             time0 = Now() + #12:00:05 AM#   '³]©w®É¶¡±±¨î­p®É5¬íÄÁ
  53.             Do
  54.                 DoEvents
  55.             Loop While (.Busy Or .readystate <> 4) And Now() < time0
  56.             
  57.             Application.Wait Time + #12:00:03 AM#
  58.             
  59.             Set E = .Document.getElementsByTagName("TABLE")(1)
  60.             If E Is Nothing Then IE.Quit: GoTo Again
  61.             
  62.             For Re = 0 To 19          '¨ú19¤Ñªº¾ú¥v¬ö¿ý
  63.                 For Ce = 0 To 8
  64.                     Price(Re, Ce) = E.Rows(Re).Cells(Ce).innertext   '¤é´Á¡B¶}¡B°ª¡B§C¡B¦¬¡Bº¦¶^  º¦% ¦¨¥æ¶q  ¦¨¥æª÷ÃB
  65.                 Next
  66.             Next
  67.             
  68.             ActiveSheet.Cells(1, "A").Resize(20, 9).Value = Price
  69. GiveUp:
  70.         
  71.         .Quit
  72.     End With

  73. End Sub
½Æ»s¥N½X

TOP

¦^´_ 2# Scott090

À°¤j¤j¸É¥R¤@¤U¡A
1.44~51¦æ¨ºÃäÀ³¸Ó¥i¥H¥Îdocument.all(name)¨ú¥N·|¤ñ¸û²³æ
2.¥i¥H³z¹L­×§ï
https://www.cnyes.com/twstock/ps_historyprice.aspx?code=2330&ctl00$ContentPlaceHolder1$startText=2001/10/05&ctl00$ContentPlaceHolder1$endText=2018/01/09
µM«á¥Î¥~³¡¶×¤J¡A·|¤ñ¸û§Ö¡A¤]¤ñ¸û²³æ
­Ó¤H¤p¤p·Qªk¡A°Ñ¦Ò¤@¤U
Excel VBAºô­¶¸ê®Æ¦¬¶°±Ð¾Ç:
http://forum.twbts.com/thread-20848-1-1.html

TOP

¦^´_ 3# iamaraymond


    ÁÂÁ¡A§Ú±N¸Õ¸Õ¬Ý¡C
¥t¡A½Ð±Ð Excel 2013 ¤Î¥¦ªº VBA »¡©úªº¬d¸ß ¬O¡G
1.³s½u³z¹Lºô¸ô¡A
ÁÙ¬O
2. Â÷½u¡A¤w¨ã³Æ®r¤J(Built in)»¡©ú¡A¥u­n«ö F1 ´N¥i¥H

TOP

¦^´_ 3# iamaraymond

¨Ì¾Ú¤j¤jªº«ü¾É¡A­×§ï¦p¤U¡A½Ð¬Ý¬Ý¬O¤£¬O³o¼Ë¤l¡C
ÁÂÁÂ
  1. '±q¹d¦ëºô¨ú±o¾ú¥vªÑ»ù
  2. '¨Ï¥Î IE ª«¥ó
  3. 'option explicit
  4. 'option base 1

  5. Sub TestCNYES1()

  6.     Dim Price()
  7.     Dim Code
  8.     Code = "2330"
  9.    
  10.     Dim IE As Object, URL$
  11.     Dim date0 As Date, StartDate$, EndDate$, submitBTN$, timer, time0 As Date
  12.     Dim Table As Object, oDoc As Object, E
  13.     Dim Re%, Ce%, i%, k%, ColName$
  14.    
  15.     ActiveSheet.Cells.Clear
  16.    
  17.     '³]©w¸ê®Æ¶}©l¤Îµ²§ô¤é´Á
  18.     StartDate = Format(DateAdd("m", -2, Date), "yyyy/mm/dd")    '¨ú2­Ó¤ëªº¸ê®Æ¡A¬ù40µ§
  19.     EndDate = Format(Date, "yyyy/mm/dd")
  20.    
  21.     StartDate = "&ctl00$ContentPlaceHolder1$startText=" & StartDate           '¶}©l¤é´Á input name
  22.     EndDate = "&ctl00$ContentPlaceHolder1$endText=" & EndDate                  ' µ²§ô¤é´Á input name
  23. '    submitBTN = "&ctl00$ContentPlaceHolder1$submitBut=¬d¸ß"
  24.    
  25.     k = 0
  26. Again:
  27.     Set IE = CreateObject("InternetExplorer.Application")
  28.    
  29.     With IE
  30.             URL = "https://www.cnyes.com/twstock/ps_historyprice.aspx?code=" & Code & StartDate & EndDate
  31.             .Visible = False                '¤£Åã¥Ü IE
  32.             .navigate URL
  33.             
  34.             time0 = Now() + #12:00:05 AM#   '³]©w®É¶¡±±¨î­p®É5¬íÄÁ
  35.             Do
  36.                 DoEvents
  37.             Loop While (.Busy Or .readystate <> 4) And Time < time0
  38.            
  39.            '­p®É®É¶¡¨ì¤Fºô­¶¥¼·Ç³Æ¦n¡AÃö³¬­«±Ò
  40.             If .readystate <> 4 Then
  41.                 .Quit
  42.                 k = k + 1
  43.                 If k <= 2 Then GoTo Again
  44.                 GoTo GiveUp                   '¶}±Ò3¦¸³£¥¢±Ñ´N©ñ±ó
  45.             End If
  46.                         
  47. '            Set E = .Document.getElementsByTagName("TABLE")(0)
  48.             Set E = .Document.all.tags("TABLE")(0)          '³o­Óºô­¶ªº¸ê®Æªí¦³ÅÜ°Ê
  49.             If E Is Nothing Then IE.Quit: GoTo Again
  50.             
  51.             i = E.Rows.Length - 1: k = E.Rows(1).Cells.Length - 1
  52.             ReDim Price(0 To i, 0 To k)
  53.             
  54.             For Re = 0 To i         '¨ú19¤Ñªº¾ú¥v¬ö¿ý
  55.                 For Ce = 0 To k
  56.                     Price(Re, Ce) = E.Rows(Re).Cells(Ce).innertext   '¤é´Á¡B¶}¡B°ª¡B§C¡B¦¬¡Bº¦¶^  º¦% ¦¨¥æ¶q  ¦¨¥æª÷ÃB
  57.                 Next
  58.             Next
  59.             
  60.             ActiveSheet.Cells(1, "A").Resize(i + 1, k + 1).Value = Price
  61. GiveUp:
  62.         
  63.         .Quit
  64.     End With

  65. End Sub
½Æ»s¥N½X

TOP

¦^´_ 5# Scott090


  §Úªº¬O«öF1¤§«á·|¤Wºô§ä»¡©ú

¥t¥~§Úªº·Qªk¬O¥ÎQueryTableªº¤è¦¡
  1. Sub ªÑ»ù()

  2. [A10].CurrentRegion.Clear

  3. stockno = [B3]
  4. mydate1 = Format([B4], "YYYY/MM/DD")
  5. mydate2 = Format([B5], "YYYY/MM/DD")
  6. myurl = "https://www.cnyes.com/twstock/ps_historyprice.aspx?code=" & stockno & "&ctl00$ContentPlaceHolder1$startText=" & mydate1 & "&ctl00$ContentPlaceHolder1$endText=" & mydate2

  7. With ActiveSheet.QueryTables.Add(Connection:= _
  8.         "URL;" & myurl _
  9.         , Destination:=Range("$A$10"))
  10.         .RowNumbers = False
  11.         .FillAdjacentFormulas = False
  12.         .PreserveFormatting = False
  13.         .RefreshOnFileOpen = False
  14.         .BackgroundQuery = False
  15.         .RefreshStyle = xlOverwriteCells
  16.         .SavePassword = False
  17.         .SaveData = True
  18.         .AdjustColumnWidth = False
  19.         .RefreshPeriod = 0
  20.         .WebSelectionType = xlSpecifiedTables
  21.         .WebFormatting = xlWebFormattingNone
  22.         .WebTables = "1"
  23.         .WebPreFormattedTextToColumns = True
  24.         .WebConsecutiveDelimitersAsOne = True
  25.         .WebSingleBlockTextImport = False
  26.         .WebDisableDateRecognition = False
  27.         .WebDisableRedirections = False
  28.         .Refresh BackgroundQuery:=False
  29.         .Delete
  30.     End With
  31. End Sub
½Æ»s¥N½X
Excel VBAºô­¶¸ê®Æ¦¬¶°±Ð¾Ç:
http://forum.twbts.com/thread-20848-1-1.html

TOP

¦^´_ 6# iamaraymond


    " ..... F1¤Wºô§ä»¡©ú ....  "¡A´N¦]¬°»Ýºô¸ô³sµ²³o»ò¤£¤è«K¡A©ñ±ó¨Ï¥Î¡C

ÁÂÁ¤j¤jªº QueryTable ¼Ò¦¡¡C
¦]¦³¨ä¥Lµ{¦¡½Xªº³sµ²¨Ï¥Î©Ò¥H§Úª½±µ§â¸ê®Æ©ñ¶i°}¦C

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2018-1-30 12:47 ½s¿è

¦^´_ 6# iamaraymond
³oºô­¶¥ÎQueryTable ±o¨úªº¸ê®Æ¦³®É°_©l¤é´Á·|¤£·Ç½T,¸Õ¸Õ­×§ï°_©l¤é´Á,¬Ý¬Ý¸ê®Æ¬O§_¥¿½T

¦^´_ 7# Scott090
  1. Option Explicit
  2. Sub Ex_Ie_Copy()
  3.     Dim Code As String, Price()
  4.     Dim date0 As Date, StartDate$, EndDate$, timer, time0 As Date, IE_StartDate As String
  5.     Dim E As Object, IE As Object
  6.     Code = "2330"
  7.     time0 = Time
  8.     Application.StatusBar = "¶}±Òºô­¶...."
  9.     '³]©w¸ê®Æ¶}©l¤Îµ²§ô¤é´Á
  10.     StartDate = Format(DateAdd("m", -12 * 10, Date), "yyyy/mm/dd") '¨ú10¦~¸ê®Æµ§
  11.     If StartDate < CDate("1994/09/07") Then
  12.         MsgBox "StartDate  " & StartDate & vbLf & "¤£¥i¤p©ó" & "1994/09/07"
  13.         End
  14.     End If
  15.     EndDate = Format(Date, "yyyy/mm/dd")
  16. Set IE = CreateObject("InternetExplorer.Application")
  17.     With IE
  18.             .navigate "http://www.cnyes.com/twstock/ps_historyprice/" & Code & ".htm"
  19.             Do:          DoEvents:             Loop While .Busy Or .readystate <> 4

  20.             With .Document.getElementsByTagName("input")
  21.                  .Item("ctl00$ContentPlaceHolder1$startText").Value = StartDate ' ¶}©l¤é´Á input name
  22.                  .Item("ctl00$ContentPlaceHolder1$endText").Value = EndDate     ' µ²§ô¤é´Á input name
  23.                  .Item("ctl00$ContentPlaceHolder1$submitBut").Click
  24.             End With
  25.             Do:          DoEvents:             Loop While .Busy Or .readystate <> 4
  26.             On Error Resume Next
  27.             Do
  28.                 Err.Clear
  29.                 Set E = .Document.getElementsByTagName("TABLE")(0)
  30.                 If E.INNERTEXT <> "" Then
  31.                     If Err = 0 Then
  32.                         If Abs(DateValue(E.Rows(E.Rows.Length - 1).Cells(0).INNERTEXT) - DateValue(StartDate)) <= 15 Then
  33.                             If Err = 0 Then Exit Do
  34.                         End If
  35.                     End If
  36.                End If
  37.              DoEvents
  38.              Application.StatusBar = " µ¥­Ô ºô­¶¸ê®Æ¤¤ ... "
  39.             Loop
  40.             On Error GoTo 0
  41.             CopyToClipbox E.OUTERHTML
  42.             Application.StatusBar = StartDate & " - " & EndDate & " ¸ê®Æ¦@ " & E.Rows.Length - 1 & " Ū¨ú.." & Application.Text(Time - time0, ["m¤À:S¬í ok"])
  43.             .Quit
  44.     End With
  45. End Sub
  46. Private Sub CopyToClipbox(strText As String)    '¤å¥»«þ¨©¨ì°Å¶KªO
  47.     With CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
  48.         .SetText strText
  49.         .PutInClipboard
  50.     End With
  51.     With ActiveSheet
  52.         .UsedRange.Clear
  53.         .[A1].Select
  54.         .Paste
  55.     End With
  56. End Sub
½Æ»s¥N½X
  1. Sub Ex_Ie()
  2.     Dim Code As String, Price()
  3.     Dim StartDate$, EndDate$, time0 As Date
  4.     Dim E As Object
  5.     Dim Re%, Ce%
  6.     Code = "2330"
  7.     time0 = Time
  8.     ActiveSheet.Cells.Clear
  9.     Cells(1).Activate
  10.     Application.StatusBar = "¶}±Òºô­¶...."
  11.     '³]©w¸ê®Æ¶}©l¤Îµ²§ô¤é´Á
  12.     StartDate = Format(DateAdd("m", -12 * 10, Date), "yyyy/mm/dd") '¨ú10¦~¸ê®Æµ§
  13.     If StartDate < CDate("1994/09/07") Then
  14.         MsgBox "StartDate  " & StartDate & vbLf & "¤£¥i¤p©ó" & "1994/09/07"
  15.         End
  16.     End If
  17.     EndDate = Format(Date, "yyyy/mm/dd")
  18.    
  19.     With CreateObject("InternetExplorer.Application")
  20.             .navigate "http://www.cnyes.com/twstock/ps_historyprice/" & Code & ".htm"
  21.             Do:          DoEvents:             Loop While .Busy Or .readystate <> 4
  22.             With .Document.getElementsByTagName("input")
  23.                  .Item("ctl00$ContentPlaceHolder1$startText").Value = StartDate ' ¶}©l¤é´Á input name
  24.                  .Item("ctl00$ContentPlaceHolder1$endText").Value = EndDate     ' µ²§ô¤é´Á input name
  25.                  .Item("ctl00$ContentPlaceHolder1$submitBut").Click
  26.             End With
  27.             Do:          DoEvents:             Loop While .Busy Or .readystate <> 4
  28.             On Error Resume Next
  29.             Do
  30.                 Err.Clear
  31.                 Set E = .Document.getElementsByTagName("TABLE")(0)
  32.                 If E.INNERTEXT <> "" Then
  33.                     If Err = 0 Then
  34.                         If Abs(DateValue(E.Rows(E.Rows.Length - 1).Cells(0).INNERTEXT) - DateValue(StartDate)) <= 15 Then
  35.                             If Err = 0 Then Exit Do
  36.                         End If
  37.                     End If
  38.                 End If
  39.                 DoEvents
  40.                 Application.StatusBar = " µ¥­Ô ºô­¶¸ê®Æ¤¤ ... "
  41.             Loop
  42.             On Error GoTo 0
  43.             'ReDim Price(0 To E.Rows.Length - 1, 0 To E.Rows(0).Cells.Length - 1)
  44.             Application.StatusBar = StartDate & " - " & EndDate & " ¸ê®Æ¦@ " & E.Rows.Length - 2 & " Ū¨ú...... "
  45.             For Re = 0 To E.Rows.Length - 1 ' 19          '¨ú19¤Ñªº¾ú¥v¬ö¿ý
  46.                 For Ce = 0 To E.Rows(Re).Cells.Length - 1
  47.                     Cells(Re + 1, Ce + 1) = E.Rows(Re).Cells(Ce).INNERTEXT '¤é´Á¡B¶}¡B°ª¡B§C¡B¦¬¡Bº¦¶^  º¦% ¦¨¥æ¶q  ¦¨¥æª÷ÃB
  48.                    ' Price(Re, Ce) = E.Rows(Re).Cells(Ce).innertext   '¤é´Á¡B¶}¡B°ª¡B§C¡B¦¬¡Bº¦¶^  º¦% ¦¨¥æ¶q  ¦¨¥æª÷ÃB
  49.                 Next
  50.             Next
  51.             'ActiveSheet.Cells(1, "A").Resize(UBound(Price), UBound(Price, 2)).Value = Price
  52.         Application.StatusBar = StartDate & " - " & EndDate & " ¸ê®Æ¦@ " & E.Rows.Length - 2 & " Ū¨ú.." & Application.Text(Time - time0, ["m¤À:S¬í ok"])
  53.         .Quit
  54.     End With
  55. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

[ª©¥DºÞ²z¯d¨¥]
  • GBKEE(2018/1/31 10:48): ¬Y¨ÇÀɪѲ¼Åª¤£¨ì¸ê®Æªº±¡§Î,¥i§_¦C¥X­þ¨ÇÀɪѲ¼

¦^´_ 8# GBKEE


    ÁÂÁ GBKEE ¤j¤j ´£¨Ñªº¡G
¸ê®Æ§¹¾ã©Êªº¬dÀ˾÷¨î¡B Clip Board ªº¤èªk

¥t¡A Do
                 .......
                 Application.StatusBar = " µ¥­Ô ºô­¶¸ê®Æ¤¤ ... "
          Loop
¤¤¡A¦³®É¤£ª¾¬Æ»òª¬ªp·|¦³¬Y¨ÇÀɪѲ¼Åª¤£¨ì¸ê®Æªº±¡§Î¡A©Ò¥H»Ý­n¥Î®É¶¡­p®É¨Ó±±¨î¨Ã©ñ±ó

¦A¦¸·P®¦

TOP

¦^´_ 8# GBKEE

   ¨S¦³°O¿ý¤U¨Ó¡A¤£¹L¦n¹³¤£¬O¤@­Ó¯S©wªº¡F¦³®É¥Î¤â°Êª½±µ¥hÀˬd¤S·|¦bºô­¶¤W¥X²{¸ê®Æ
¤U¦¸¸I¨ì§â¥¦­Ì°O¤U¨Ó°eµ¹°Ñ¦Ò¡C
§Ú¦bÃhºÃ¬Oºô¸ô¥»¨­ªº¶Ç¿é¤]»¡¤£©w

ÁÂÁÂ

TOP

        ÀR«ä¦Û¦b : °µ¦n¨Æ¤£¯à¤Ö§Ú¤@¤H¡A°µÃa¨Æ¤£¯à¦h§Ú¤@¤H¡C
ªð¦^¦Cªí ¤W¤@¥DÃD