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

[µo°Ý] ¦³¿ìªk±N¨C¤é¸ê®Æ·|¦¨¤@¥÷¹À

[µo°Ý] ¦³¿ìªk±N¨C¤é¸ê®Æ·|¦¨¤@¥÷¹À

±z¦n
§Ú§Æ±æ¥i¥H§â¨C¤éªº¸ê®Æ·J¾ã¦¨¤@¥÷
½Ð¤j®aÀ°¹À«ü¾É
ÁÂÁÂ!!
  1. Sub GetData()

  2.     Dim DataSheet As Worksheet
  3.     Dim EndDate As Date
  4.     Dim StartDate As Date
  5.     Dim Symbol As String
  6.     Dim qurl As String
  7.     Dim nQuery As Name
  8.    
  9.     Application.ScreenUpdating = False
  10.     Application.DisplayAlerts = False
  11.     Application.Calculation = xlCalculationManual
  12.    
  13.     Set DataSheet = ActiveSheet
  14.   
  15.         StartDate = DataSheet.Range("B1").Value
  16.         EndDate = DataSheet.Range("B2").Value
  17.         Symbol = DataSheet.Range("B3").Value
  18.         Range("C7").CurrentRegion.ClearContents
  19.         
  20.         qurl = "http://www.twse.com.tw/ch/trading/exchange/BWIBBU/BWIBBU.php?" & Symbol
  21.         qurl = qurl & "&a=" & Month(StartDate) - 1 & "&b=" & Day(StartDate) & _
  22.             "&c=" & Year(StartDate) & "&d=" & Month(EndDate) - 1 & "&e=" & _
  23.             Day(EndDate) & "&f=" & Year(EndDate) & "&g=" & Range("E3") & "&q=q&y=0&z=" & _
  24.             Symbol & "&x=.csv"
  25.                   
  26. QueryQuote:
  27.             With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=DataSheet.Range("C7"))
  28.                  .AdjustColumnWidth = False
  29.                 .BackgroundQuery = True
  30.                 .TablesOnlyFromHTML = False
  31.                 .Refresh BackgroundQuery:=False
  32.                 .SaveData = True
  33.                
  34.             End With
  35.             
  36.             Range("C7").CurrentRegion.TextToColumns Destination:=Range("C7"), DataType:=xlDelimited, _
  37.                 TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
  38.                 Semicolon:=False, Comma:=True, Space:=False, other:=False
  39.             
  40.             Range(Range("C7"), Range("C7").End(xlDown)).NumberFormat = "yyyy/mm/dd"
  41.             Range(Range("D7"), Range("G7").End(xlDown)).NumberFormat = "0.00"

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

test.rar (30.19 KB)

¥»©«³Ì«á¥Ñ GBKEE ©ó 2013-9-20 11:47 ½s¿è

¦^´_ 1# pupai
¦p¦ó¨C¤é¸ê®Æ¶×¦¨¤@¥÷??
  1. §Aªººô§}¤Ö¤F STK_NO (ªÑ²¼¥N¸¹)
  2. 'qurl = qurl & "&a=" & Month(StartDate) - 1 & "&b=" & Day(StartDate) & _
  3.             "&c=" & Year(StartDate) & "&d=" & Month(EndDate) - 1 & "&e=" & _
  4.             Day(EndDate) & "&f=" & Year(EndDate) & "&g=" & Range("E3") & "&q=q&y=0&z=" & _
  5.             Symbol & "&x=.csv"
  6.             '*** ¤W­±ªººô§}qurl ¬°¦ó­n a= b= c= d= e= ³o¨Ç  ******
  7.              qurl = "http://www.twse.com.tw/ch/trading/exchange/BWIBBU/BWIBBU.php?myear=2013&mmon=9&STK_NO=2371"         

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

TOP

¦^´_ 2# GBKEE


    G¤jÁÙ¬O¤£¦æ
  1. Sub GetData()

  2.     Dim DataSheet As Worksheet
  3.     Dim EndDate As Date
  4.     Dim StartDate As Date
  5.     Dim Symbol As String
  6.     Dim qurl As String
  7.     Dim nQuery As Name
  8.    
  9.     Application.ScreenUpdating = False
  10.     Application.DisplayAlerts = False
  11.     Application.Calculation = xlCalculationManual
  12.    
  13.     Set DataSheet = ActiveSheet
  14.   
  15.         StartDate = DataSheet.Range("B1").Value
  16.         EndDate = DataSheet.Range("B2").Value
  17.         Symbol = DataSheet.Range("B3").Value
  18.         Range("C7").CurrentRegion.ClearContents
  19.         
  20.         qurl = qurl & "&a=" & Month(StartDate) - 1 & "&b=" & Day(StartDate) & _
  21.             "&c=" & Year(StartDate) & "&d=" & Month(EndDate) - 1 & "&e=" & _
  22.             Day(EndDate) & "&f=" & Year(EndDate) & "&g=" & Range("E3") & "&q=q&y=0&z=" & _
  23.             Symbol & "&x=.csv"
  24.             '*** ¤W­±ªººô§}qurl ¬°¦ó­n a= b= c= d= e= ³o¨Ç  ******
  25.              qurl = "http://www.twse.com.tw/ch/trading/exchange/BWIBBU/BWIBBU.php?myear=2013&mmon=9&STK_NO=2371"   
  26.                   
  27. QueryQuote:
  28.             With ActiveSheet.QueryTables.Add(Connection:="URL;" & qurl, Destination:=DataSheet.Range("C7"))
  29.                  .AdjustColumnWidth = False
  30.                 .BackgroundQuery = True
  31.                 .TablesOnlyFromHTML = False
  32.                 .Refresh BackgroundQuery:=False
  33.                 .SaveData = True
  34.                
  35.             End With
  36.             
  37.             Range("C7").CurrentRegion.TextToColumns Destination:=Range("C7"), DataType:=xlDelimited, _
  38.                 TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
  39.                 Semicolon:=False, Comma:=True, Space:=False, other:=False
  40.             
  41.             Range(Range("C7"), Range("C7").End(xlDown)).NumberFormat = "yyyy/mm/dd"
  42.             Range(Range("D7"), Range("G7").End(xlDown)).NumberFormat = "0.00"

  43. End Sub
½Æ»s¥N½X
¥¼©R¦W.JPG

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2013-9-20 12:27 ½s¿è

¦^´_ 3# pupai
½Ð¸Ô¬Ý¹Ï¥Üªº¿ù»~«H®§,¥h¬Ý¬ÝÀx¦s®æªº½d³ò,¤£ª¾§A­n¦p¦ó¨C¤é¸ê®Æ¶×¦¨¤@¥÷??
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 4# GBKEE


    ¤£À´
¥i§_¸Ô²Ó»¡©ú
ÁÂÁÂ!!

TOP

¦^´_ 4# GBKEE

G¤j
    ¨º½Ð°Ý¦³¿ìªk§âhttp://www.twse.com.tw/ch/trading/exchange/BWIBBU/BWIBBU.phpªº¸ê®Æ
¥ÎVBªº¤è¦¡§@¦¨¥i¥H¬d¸ßªÑ²¼¥N½X¥B¦³³sÄò®É¶¡ªº¤@¥÷¸ê®Æ(¤ñ¤è:2009/01/01¨ì2013/09/18 )
ÁÂÁÂ

TOP

¦^´_ 6# pupai
  1. Option Explicit
  2. Sub GetData()
  3.     Dim DataSheet As Worksheet, Sh As Worksheet, Msg As Boolean
  4.     Dim EndDate As Date, StartDate As Date, i As Integer, AR, xR As Long
  5.     Dim Symbol As String, Qur As String
  6.     Set DataSheet = Sheets("Sheet1")
  7.     With DataSheet
  8.         StartDate = .[b1]
  9.         EndDate = .[b2]
  10.         Symbol = .[b3]
  11.         .Range("D1").CurrentRegion = ""
  12.     End With
  13.     '¥»¸ê®Æ¦Û¥Á°ê94¦~09¤ë01¤é¶}©l´£¨Ñ *** °£¿ù  ***
  14.     If StartDate < #9/1/2005# Or EndDate < #9/1/2005# Or Len(Symbol) <= 3 Or StartDate > EndDate Or EndDate > Date Then
  15.         MsgBox "¼Æ¾Ú¦³»~" & IIf(StartDate < #9/1/2005#, vbLf & "StartDate :¤é´Á ¤p©ó 94¦~09¤ë01¤é  ", "") & _
  16.         IIf(EndDate < #9/1/2005#, vbLf & "EndDate :¤é´Á ¤p©ó 94¦~09¤ë01¤é  ", "") & _
  17.         IIf(Len(Symbol) <= 3, vbLf & "Symbol : ªÑ²¼¥N¸¹ ", "") & _
  18.         IIf(StartDate > EndDate, vbLf & "StartDate > EndDate", "") & _
  19.         IIf(EndDate > Date, vbLf & " EndDate >" & Date, "")
  20.         Exit Sub
  21.     End If
  22.     '*********************************************
  23.     Set Sh = Sheets.Add(Sheets(1))
  24.     DataSheet.Activate
  25.     Do While DateSerial(Year(StartDate), Month(StartDate), 1) <= EndDate
  26.         Qur = "http://www.twse.com.tw/ch/trading/exchange/BWIBBU/BWIBBU.php?myear=" & Format(StartDate, "yyyy") & "&mmon=" & Format(StartDate, "m") & "&STK_NO=" & Symbol
  27.         With Sh
  28.             If .QueryTables.Count = 0 Then
  29.                 .QueryTables.Add "URL;" & Qur, .[A1]
  30.             Else
  31.                 .QueryTables(1).Connection = "URL;" & Qur
  32.                 Msg = True
  33.             End If
  34.            With .QueryTables(1)
  35.                 .WebFormatting = xlWebFormattingNone
  36.                 .WebSelectionType = xlSpecifiedTables
  37.                 .WebDisableDateRecognition = True
  38.                 .WebTables = "8"
  39.                  .Refresh BackgroundQuery:=False
  40.                  If Application.CountA(.ResultRange) = 0 Then Msg = False
  41.                  If Msg Then
  42.                     AR = .ResultRange.Offset(2)
  43.                  Else
  44.                     AR = .ResultRange
  45.                  End If
  46.                  With DataSheet
  47.                     xR = Application.CountA(.[d:d]) + 1
  48.                     .Cells(xR, "D").Resize(UBound(AR, 1), UBound(AR, 2)) = AR
  49.                  End With
  50.            End With
  51.            End With
  52.         StartDate = DateAdd("m", 1, StartDate)
  53.     Loop
  54.     Application.DisplayAlerts = False
  55.     Sh.Delete
  56.     Application.DisplayAlerts = True
  57. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 7# GBKEE


½Ð±Ð G¤j
®Ú¾Ú¤W­±°õ¦æ«ástartdate»Penddate¦n¹³¦³°ÝÃD
¶]¤£¥X¨Ó
µ²ªG¦pªþ¥ó
ÁÂÁÂ!!
¥¼©R¦W.JPG

TOP

¦^´_ 8# pupai
¨S¦³°Ú!
¹Ï¥Ü¬° °õ¦æ 7# µ{¦¡½X ªºµ²ªG


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

TOP

¦^´_ 9# GBKEE


    ¥i¥H¤F~~·P®¦!!

TOP

        ÀR«ä¦Û¦b : ¤£©È¨Æ¦h¡A¥u©È¦h¨Æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD