- ©«¤l
- 1
- ¥DÃD
- 1
- ºëµØ
- 0
- ¿n¤À
- 2
- ÂI¦W
- 0
- §@·~¨t²Î
- win7
- ³nÅ骩¥»
- 64
- ¾\ŪÅv
- 10
- µù¥U®É¶¡
- 2016-4-1
- ³Ì«áµn¿ý
- 2016-4-4
|
[µo°Ý] QueryTables ¬d¸ßªÑ²¼°ÝÃD
¦U¦ì°ª¤â±M®a¦n
¤p§Ì¦b¨Ï¥ÎQueryTable ®É¡A
·|¦b³sÄò¬d¸ß¼Æµ§¸ê®Æ¤§«á¬ðµMµo¥Í 400 ªº¿ù»~¡A¦Ó³y¦¨¸ê®Æ¤@ª½¬d¤£§¹¡A·Q½Ð±Ð¬Oµo¥Í¤°»ò°ÝÃD©O?
µ{¦¡½X©MªþÀɦp¤U ·PÁ¦^ÂÐ
Sub §ì¨úªÑ²¼¸ê®Æ()
Dim StartTime
Dim i
Dim j
Dim StockNumber As String 'ªÑ²¼¥N¸¹
i = 2
If ½T»{¤u§@ªí¦s¦b("Temp") <> True Then
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Temp"
End If
Application.ScreenUpdating = False
²M°£¤u§@ªí ("Temp")
Set Tempsheet = Sheets("Temp")
Do While Sheet1.Cells(i, 1) <> ""
If Sheet1.Cells(i, 2) = "" Then
StockNumber = Sheet1.Cells(i, 1)
GetCurrentPrice (StockNumber)
End If
Sheet1.Cells(i, 2) = StockName
Sheet1.Cells(i, 3) = CurrentPrice
Sheet1.Cells(i, 4) = PriceChange
Sheet1.Cells(i, 5) = StockQuantity
i = i + 1
Loop
Application.StatusBar = "ªÑ²¼¸ê®Æ§ì¨ú§¹¦¨"
Application.ScreenUpdating = True
Sheet1.Activate
Sheets("Temp").Delete
End Sub
Sub GetCurrentPrice(StockNumber As String)
Dim ur As String
Application.StatusBar = "¨ú±oªÑ²¼ " & StockNumber & " ªÑ»ù¸ê®Æ¤¤......"
ur = "https://tw.finance.yahoo.com/q/q?s=" & StockNumber
' MsgBox ur
Tempsheet.Range("A:L").Clear
With Tempsheet.QueryTables.Add(Connection:="URL;" & ur, Destination:=Tempsheet.Range("A1"))
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "6"
.Refresh BackgroundQuery:=False
.Delete
End With
StockName = Tempsheet.Cells(3, 1)
CurrentPrice = Tempsheet.Cells(3, 3)
PriceChange = Tempsheet.Cells(3, 6)
StockQuantity = Tempsheet.Cells(3, 7)
End Sub
Book1.zip (19.95 KB)
|
|