- ©«¤l
- 184
- ¥DÃD
- 45
- ºëµØ
- 0
- ¿n¤À
- 407
- ÂI¦W
- 0
- §@·~¨t²Î
- WIN 7
- ³nÅ骩¥»
- office 2010
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2010-8-19
- ³Ì«áµn¿ý
- 2024-11-1
|
- µ{¦¡§Ú¤j·§»¡©ú¤@¤U
- Option Explicit
- Sub GetData()
- Dim DataSheet As Worksheet, Sh As Worksheet, Msg As Boolean '©w¸qÅܼÆ
- Dim EndDate As Date, StartDate As Date, i As Integer, AR, xR As Long '©w¸qÅܼÆ
- Dim Symbol As String, Qur As String '©w¸qÅܼÆ
- Set DataSheet = Sheets("Sheet1") '³]©w¤u§@ªí¦WºÙ
- With DataSheet
- StartDate = .[b1] '±NB1Äæ¦ìÈŪ¨ìÅܼÆStartDate¤¤
- EndDate = .[b2] '±NB2Äæ¦ìÈŪ¨ìÅܼÆEndDate¤¤
- Symbol = .[b3] '±NB3Äæ¦ìÈŪ¨ìÅܼÆSymbol¤¤
- .Range("D1").CurrentRegion = "" '³]©wD1Äæ¦ìÈ
- End With
- '¥»¸ê®Æ¦Û¥Á°ê94¦~09¤ë01¤é¶}©l´£¨Ñ *** °£¿ù *** '¥H¤U¥H94/09/01¬°¬É,§PŪ¿é¤JȬO§_¦³¿ù
- If StartDate < #9/1/2005# Or EndDate < #9/1/2005# Or Len(Symbol) <= 3 Or StartDate > EndDate Or EndDate > Date Then
- MsgBox "¼Æ¾Ú¦³»~" & IIf(StartDate < #9/1/2005#, vbLf & "StartDate :¤é´Á ¤p©ó 94¦~09¤ë01¤é ", "") & _
- IIf(EndDate < #9/1/2005#, vbLf & "EndDate :¤é´Á ¤p©ó 94¦~09¤ë01¤é ", "") & _
- IIf(Len(Symbol) <= 3, vbLf & "Symbol : ªÑ²¼¥N¸¹ ", "") & _
- IIf(StartDate > EndDate, vbLf & "StartDate > EndDate", "") & _
- IIf(EndDate > Date, vbLf & " EndDate >" & Date, "")
- Exit Sub
- End If
- '*********************************************
- Set Sh = Sheets.Add(Sheets(1))
- DataSheet.Activate
- Do While DateSerial(Year(StartDate), Month(StartDate), 1) <= EndDate ' DO¨ìLOOP¤¤ªºµ{¦¡¬°¥H¿é¤JÈ¥h§ì¨úºô¶ªº¸ê®Æ
- Qur = "http://www.twse.com.tw/ch/trading/exchange/BWIBBU/BWIBBU.php?myear=" & Format(StartDate, "yyyy") & "&mmon=" & Format(StartDate, "m") & "&STK_NO=" & Symbol
- With Sh
- If .QueryTables.Count = 0 Then
- .QueryTables.Add "URL;" & Qur, .[A1]
- Else
- .QueryTables(1).Connection = "URL;" & Qur
- Msg = True
- End If
- With .QueryTables(1)
- .WebFormatting = xlWebFormattingNone
- .WebSelectionType = xlSpecifiedTables
- .WebDisableDateRecognition = True
- .WebTables = "8"
- .Refresh BackgroundQuery:=False
- If Application.CountA(.ResultRange) = 0 Then Msg = False
- If Msg Then
- AR = .ResultRange.Offset(2)
- Else
- AR = .ResultRange
- End If
- With DataSheet
- xR = Application.CountA(.[d:d]) + 1
- .Cells(xR, "D").Resize(UBound(AR, 1), UBound(AR, 2)) = AR
- End With
- End With
- End With
- StartDate = DateAdd("m", 1, StartDate) '³o¦æ´N¬O¯à§ì¸ó¤ëªºpºâ¦¡,§ì§¹²Ä¤@Ó¤ë«á,ÅܼÆStartDateªº¤ë¥÷+1
- Loop
- Application.DisplayAlerts = False
- Sh.Delete
- Application.DisplayAlerts = True
- End Sub
½Æ»s¥N½X ¤À¨ÉG¤jªºµ{¦¡½X |
|