poizxc_teng wrote:
請教各位高手,我要如...(恕刪)


很弱的磚塊也拋一塊出來,供您參考



current_year = Format(Date, "yyyy")
current_month = Format(Date, "mm")
taiex_date = Format(Date, "mmdd")
OTC_date = OTC_year + taiex_date

TSE_open = "http://www.twse.com.tw/ch/trading/exchange/MI_INDEX/genpage/Report" _
+ current_year + current_month + "/A112" + current_year + taiex_date + "ALLBUT0999_1.php?select2=ALLBUT0999&chk_date=" + OTC_date

Workbooks.Open Filename:=TSE_open

我是用最簡單的『開啟檔案』的方式,來抓取證交所的資料
缺點就是,只能在每天的14:00收盤產生資料後,才抓得到資料。

我自己是錄製了一個巨集,然後每天14:00以後就開啟並執行它,讓股價資料
自動更新。
上市抓取

YY = Year(Now)
MM = Month(Now)
DD = Day(Now)
Week = Weekday(DD)


YMD1 = YY & MM
YMD1 = 201212

YMD2 = YY & MM & DD - 1
YMD2 = 20121212(-1) = 20121211(前一天)

YMD3 = YY - 1911 & "/" & MM & "/" & DD - 1
YMD3 = 2012(-1911)/12/12(-1) = 101/12/11


With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.twse.com.tw/ch/trading/exchange/MI_INDEX/genpage/Report" & YMD1 & "/A112" & YMD2 & "ALLBUT0999_1.php?select2=ALLBUT0999&chk_date=" & YMD3 & "#", Destination _
:=Range("A1000"))
.AdjustColumnWidth = False
.WebTables = 10
.RefreshStyle = xlOverwriteCell
.Refresh BackgroundQuery:=False
.Refresh (False)
End With
上櫃抓取

YY = Year(Now)
MM = Month(Now)
DD = Day(Now)

YMD1 = YY-1911 & MM & DD-1 (前一天)
YMD1 = 2012(-1911)1212(-1) = 1011211


With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.otc.org.tw/ch/stock/aftertrading/otc_quotes_no1430/squote_ew_" & YMD1 & ".html", Destination _
:=Range("A1"))
.AdjustColumnWidth = False
.RefreshStyle = xlOverwriteCell
.Refresh BackgroundQuery:=False
.Refresh (False)
End With
poizxc_teng wrote:
請教各位高手,我要如...(恕刪)


使用方法:

資料 => 從其他來源 => 從XML資料匯入 => 貼上以下這個連結

http://ichart.finance.yahoo.com/table.csv?s=0050.TW&a=11&b=31&c=2001&d=10&e=9&f=2099&g=m&ignore=.csv

會自動更新(匯入時記得勾選自動更新)

(同理,把 0050.TW 代換成其他股票代碼就OK囉)
謝謝大大的分享,我試了一下,改成這樣子才會work.

=Range("$A$1")) , 還是謝謝大大的分享.....感恩.

文章分享
評分
評分
複製連結

今日熱門文章 網友點擊推薦!