問題:
再按一次 Alt+F11 回到 Excel, 按 Alt+F8 選 GetStoeckInfo 履行它, 便可在工作表裡看到功效。
程式重點:
解答:
Sub GetStockInfo()
Call 法人持股("2330"翻譯社 "sheet1"翻譯社 "A1")
Call 法人持股("2340"翻譯社 "sheet1", "A35")
- 法人持股是 corporation.cfm, 六日行情是 quote6day.cfm, 信用買賣是 trust.cfm, 這些是從">阿誰 fortune.wls.com.tw 的網頁上看來的。
- scode 這個參數可從實際操作或從網頁原始碼看出來 。
- .WebSelectionType = xlSpecifiedTables 示意不抓整頁, 只抓頁面上某些表格翻譯
- .WebTables = "7" 示意要抓的是頁面上第7個表格。
- .Name 的內容文字可以自由決意。
- 參考: >抓取台北期交所 (Taifex) 網站供給的資訊(上) ; >抓取台北期交所 (Taifex) 網站供給的資訊(下)
Call 信譽生意業務("2330", "sheet3", "A1")
Call 信用生意業務("2340", "sheet3", "A25")End Sub
Sub GetWls(cfm As String翻譯社 tbl As String翻譯社 stock As String翻譯社 tsheet As String翻譯社 tcell As String)
With Worksheets(tsheet).QueryTables.Add(Connection:= _
"URL;http://fortune.wls.com.tw/stock/company/" & cfm & "?scode=" & stock, _
Destination:=Worksheets(tsheet).Range(tcell))
.Name = cfm & "_" & stock
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = tbl
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub