- ©«¤l
- 5923
- ¥DÃD
- 13
- ºëµØ
- 1
- ¿n¤À
- 5986
- ÂI¦W
- 0
- §@·~¨t²Î
- win10
- ³nÅ骩¥»
- Office 2010
- ¾\ŪÅv
- 150
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥xÆW°ò¶©
- µù¥U®É¶¡
- 2010-5-1
- ³Ì«áµn¿ý
- 2022-1-23
|
¥»©«³Ì«á¥Ñ GBKEE ©ó 2013-10-23 16:18 ½s¿è
¦^´_ 19# pupai - Option Explicit
- Sub GetData()
- Dim DataSheet As Worksheet, Sh As Worksheet
- Dim EndDate As Date, StartDate As Date, AR, xR As Long
- Dim Symbol As Variant, Qur As String
- Set DataSheet = Sheets("¥N½X")
- With DataSheet
- StartDate = .[C1]
- EndDate = .[C2]
- '¥»¸ê®Æ¦Û¥Á°ê94¦~09¤ë01¤é¶}©l´£¨Ñ *** °£¿ù ***
- If StartDate < #9/1/2005# Or EndDate < #9/1/2005# 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(StartDate > EndDate, vbLf & "StartDate > EndDate", "") & _
- IIf(EndDate > Date, vbLf & " EndDate >" & Date, "")
- Exit Sub
- End If
- '*********************************************
- Application.DisplayAlerts = False
- For Each Sh In Sheets
- If Sh.Name <> DataSheet.Name Then Sh.Delete '§R°£¤£¥²nªº¤u§@
- Next
- For Each Symbol In .Range("A2", .Range("A" & .Rows.Count).End(xlUp)) 'ªÑ²¼ªº°j°é
- StartDate = .[C1] '°j°é»Ý«·s¦^¨ì쥻ªº StartDate¤é´Á
- Set Sh = Sheets.Add(, Sheets(Sheets.Count)) '·s¼Wªº¤u§@ªí¦ì©ó¬¡¶Ã¯³Ì«á±(Sheets.Count)
- DataSheet.Activate
- Do While DateSerial(Year(StartDate), Month(StartDate), 1) <= EndDate
- 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 '·s¼Wªº¤u§@ªí
- If .QueryTables.Count = 0 Then 'Web¬d¸ß
- .QueryTables.Add "URL;" & Qur, .[M1] 'Web¬d¸ß¸ê®Æ¦bMÄæ
- Else
- .QueryTables(1).Connection = "URL;" & Qur
- End If
- With .QueryTables(1)
- .WebFormatting = xlWebFormattingNone
- .WebSelectionType = xlSpecifiedTables
- .WebDisableDateRecognition = True
- .WebTables = "7,8"
- .Refresh BackgroundQuery:=False
- If Application.CountA(.ResultRange) > 1 Then
- AR = .ResultRange.Offset(4)
- If Application.CountA(.Parent.[a:a]) = 0 Then AR = .ResultRange.Offset(3)
- xR = Application.CountA(.Parent.[a:a]) + 1 '.Parent :Web¬d¸ßªº¤÷¼h
- .Parent.Cells(xR, "A").Resize(UBound(AR, 1), UBound(AR, 2)) = AR '¸ê®Æ½Æ»s¨ì ·s¼W¤u§@ªíªºAÄæ
- End If
- End With
-
- End With
- StartDate = DateAdd("m", 1, StartDate) '¤é´Á + 1Ó¤ë
- Loop
- With Sh
- .Name = Symbol '¥HªÑ²¼©R¦W
- '------------------------
- .Activate
- .Range("E3").Select
- ActiveCell.FormulaR1C1 = _
- "=IF(ISERROR(DATEVALUE(1911+MID(RC[-4],1,FIND(""/"",RC[-4])-1) & MID(RC[-4],FIND(""/"",RC[-4]),LEN(RC[-4])))),"""",DATEVALUE(1911+MID(RC[-4],1,FIND(""/"",RC[-4])-1) & MID(RC[-4],FIND(""/"",RC[-4]),LEN(RC[-4]))))"
- .Range("E3").Select
- Selection.Copy
- .Columns("E:E").Select
- ActiveSheet.Paste
- .Columns("E:E").Select
- Selection.NumberFormatLocal = "[$-404]e/m/d;@"
- '------------------------
- .QueryTables(1).ResultRange = "" '²M°£Web¬d¸ßªº¸ê®Æ
- .Names(.QueryTables(1).Name).Delete 'Web¬d¸ßªº¦WºÙ
- End With
- Next
- End With
- Application.DisplayAlerts = True
- End Sub
½Æ»s¥N½X |
|