標題:
期貨交易所鉅額股票期貨資料頡取
[打印本頁]
作者:
chwqk
時間:
2014-12-6 22:33
標題:
期貨交易所鉅額股票期貨資料頡取
期貨交易所網站
http://www.taifex.com.tw/chinese/3/3_3_3.asp
契約:股票期貨
只能看
EXCEL查詢又回到
契約:台指期貨(TX)
有辦法 EXCEL VBA 頡取 契約:股票期貨 嗎??????!!!!!
請教高手們.......
作者:
GBKEE
時間:
2014-12-7 07:13
回復
1#
chwqk
Option Explicit
Sub Ex_台期_各商品成交資訊()
Dim E As Object, i As Integer, ii As Integer, K As Integer
Dim xadte As Date
xadte = DateAdd("yyyy", -1, Date) '日期(起):
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate "http://www.taifex.com.tw/chinese/3/3_3_3.asp"
Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
'<OPTION value="TX" selected>台股期貨(TX)</OPTION>
'<OPTION value="MTX" >小型台指(MTX)</OPTION>
'<OPTION value="TXO" >台指選擇權(TXO)</OPTION>
'<OPTION value="STF" >股票期貨</OPTION>
.document.ALL("commodity_idt").Value = "STF" '契約: 股票期貨
With .document.getElementsByTAGName("INPUT")
.Item("datestart").Value = Format(xadte, "YYYY/MM/DD")
.Item("dateend").Value = Format(Date, "YYYY/MM/DD")
.Item("button3").Click
End With
Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
Set E = .document.getElementsByTAGName("TABLE")(3)
ActiveSheet.UsedRange.Clear
For i = 0 To E.Rows.Length - 1
K = K + 1
For ii = 0 To E.Rows(i).Cells.Length - 1
Cells(K, ii + 1) = E.Rows(i).Cells(ii).INNERTEXT
Next
Next
.Quit '關閉網頁
End With
End Sub
複製代碼
作者:
leoncc
時間:
2015-5-24 19:13
回復
2#
GBKEE
不好意思再PO一次
Option Explicit
Sub Ex_台期_各商品成交資訊()
Dim E As Object, i As Integer, ii As Integer, K As Integer
Dim xadte As Date
xadte = DateAdd("yyyy", -1, Date) '日期(起):
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate "http://www.taifex.com.tw/chinese/3/7_12_6.asp"
Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
'<OPTION value="TX" selected>台股期貨(TX)</OPTION>
'<OPTION value="MTX" >小型台指(MTX)</OPTION>
'<OPTION value="TXO" >台指選擇權(TXO)</OPTION>
'<OPTION value="STF" >股票期貨</OPTION>
'.document.ALL("commodity_idt").Value = "STF" '契約: 股票期貨
With .document.getElementsByTAGName("INPUT")
.Item("datestart").Value = Format(xadte, "YYYY/MM/DD")
.Item("dateend").Value = Format(Date, "YYYY/MM/DD")
.Item("button4").Click
End With
Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
Set E = .document.getElementsByTAGName("TABLE")(3)
ActiveSheet.UsedRange.Clear
For i = 0 To E.Rows.Length - 1
K = K + 1
For ii = 0 To E.Rows(i).Cells.Length - 1
Cells(K, ii + 1) = E.Rows(i).Cells(ii).INNERTEXT
Next
Next
.Quit '關閉網頁
End With
End Sub
複製代碼
作者:
GBKEE
時間:
2015-5-26 08:17
回復
3#
leoncc
這網頁是要下載檔案
Option Explicit
Sub Ex_台期_各商品成交資訊()
Dim xDate(1 To 2) As Date, xPath As String, wB As String
'IE 下載檔案的資料夾
xPath = "C:\Documents and Settings\hsu\My Documents\"
'清空 下載檔案的資料夾 的csv檔
If Dir(xPath & "*.csv") <> "" Then Kill xPath & "*.csv"
xDate(1) = DateAdd("yyyy", -1, Date) '日期(起):
xDate(2) = Date '日期(迄):
If Weekday(Date, vbMonday) >= 6 Then '當日非營業日
Do While Weekday(Date, vbMonday) >= 6
xDate(2) = xDate(2) - 1
Loop
ElseIf Time < #3:00:00 PM# Then
xDate(2) = xDate(2) - 1 '當日大盤資料尚未整理完畢
End If
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate "http://www.taifex.com.tw/chinese/3/7_12_6.asp"
Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
'<OPTION value="TX" selected>台股期貨(TX)</OPTION>
'<OPTION value="MTX" >小型台指(MTX)</OPTION>
'<OPTION value="TXO" >台指選擇權(TXO)</OPTION>
'<OPTION value="STF" >股票期貨</OPTION>
'.document.ALL("commodity_idt").Value = "STF" '契約: 股票期貨
With .document.getElementsByTAGName("INPUT")
.Item("datestart").Value = Format(xDate(1), "YYYY/MM/DD")
.Item("dateend").Value = Format(xDate(2), "YYYY/MM/DD")
.Item("button4").Click
End With
Application.Wait Now + #12:00:02 AM#
Application.SendKeys "%s", True
Application.Wait Now + #12:00:01 AM# '如VBA執行速度快,可延長秒數
Application.SendKeys "%s", True
.Quit '關閉網頁
End With
wB = Dir(xPath & "*.csv")
If wB <> "" Then Workbooks.Open (xPath & wB) '開啟下載的檔案
End Sub
複製代碼
作者:
leoncc
時間:
2015-5-28 17:51
回復
4#
GBKEE
謝謝G大回覆,但可能要再麻煩G大了,小弟執行後,無任何錯誤、但也無任何資料,檔案仍是空白。 小弟試過更改存檔路徑,但仍是空白。不勝感激
作者:
GBKEE
時間:
2015-5-29 09:33
回復
5#
leoncc
IE8下載檔案資料夾, 須是前一次下載檔案資料夾
如圖
[attach]21059[/attach]
IE8 如不這選項不勾選
[attach]21060[/attach]
可直接開啟檔案(IE8 以上的IE 也可以試看看
With .document.getElementsByTAGName("INPUT")
.Item("datestart").Value = Format(xDate(1), "YYYY/MM/DD")
.Item("dateend").Value = Format(xDate(2), "YYYY/MM/DD")
.Item("button4").Click
End With
Application.Wait Now + #12:00:02 AM#
Application.SendKeys "%s", True '儲存
Application.Wait Now + #12:00:02 AM# '如VBA執行速度快,可延長秒數
Application.SendKeys "%s", True '另存新檔
Application.Wait Now + #12:00:02 AM#
Application.SendKeys "%O", True ' ***開啟檔案***
.Quit '關閉網頁
複製代碼
這段程式碼可刪除
xPath = "C:\Documents and Settings\hsu\My Documents\"
If Dir(xPath & "*.csv") <> "" Then Kill xPath & "*.csv"
'*************
wB = Dir(xPath & "*.csv")
If wB <> "" Then Workbooks.Open (xPath & wB) '開啟下載的檔案
複製代碼
作者:
leoncc
時間:
2015-6-1 10:46
回復
6#
GBKEE
G大您好
早上10:40測試了一下,還是出現下列錯誤:
[attach]21074[/attach]
除上述錯誤外,檔案並無任何動作,也沒有G大所述下載檔案的視窗。
另外跟G大報告,我的是IE11,要再麻煩G大了 不好意思
原始碼:
Option Explicit
Sub Ex_台期_各商品成交資訊()
Dim xDate(1 To 2) As Date, xPath As String, wB As String
'IE 下載檔案的資料夾
' xPath = "C:\Documents and Settings\hsu\My Documents\"
'清空 下載檔案的資料夾 的csv檔
'If Dir(xPath & "*.csv") <> "" Then Kill xPath & "*.csv"
xDate(1) = DateAdd("yyyy", -1, Date) '日期(起):
xDate(2) = Date '日期(迄):
If Weekday(Date, vbMonday) >= 6 Then '當日非營業日
Do While Weekday(Date, vbMonday) >= 6
xDate(2) = xDate(2) - 1
Loop
ElseIf Time < #3:00:00 PM# Then
xDate(2) = xDate(2) - 1 '當日大盤資料尚未整理完畢
End If
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate "http://www.taifex.com.tw/chinese/3/7_12_6.asp"
Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
'<OPTION value="TX" selected>台股期貨(TX)</OPTION>
'<OPTION value="MTX" >小型台指(MTX)</OPTION>
'<OPTION value="TXO" >台指選擇權(TXO)</OPTION>
'<OPTION value="STF" >股票期貨</OPTION>
'.document.ALL("commodity_idt").Value = "STF" '契約: 股票期貨
With .document.getElementsByTAGName("INPUT")
.Item("datestart").Value = Format(xDate(1), "YYYY/MM/DD")
.Item("dateend").Value = Format(xDate(2), "YYYY/MM/DD")
.Item("button4").Click
End With
Application.Wait Now + #12:00:02 AM#
Application.SendKeys "%s", True '儲存
Application.Wait Now + #12:00:02 AM# '如VBA執行速度快,可延長秒數
Application.SendKeys "%s", True '另存新檔
Application.Wait Now + #12:00:02 AM#
Application.SendKeys "%O", True ' ***開啟檔案***
.Quit '關閉網頁
End With
' wB = Dir(xPath & "*.csv")
'If wB <> "" Then Workbooks.Open (xPath & wB) '開啟下載的檔案
End Sub
複製代碼
作者:
GBKEE
時間:
2015-6-1 14:09
本帖最後由 GBKEE 於 2015-6-1 14:10 編輯
回復
7#
leoncc
再試試看
Option Explicit
Sub Ex_台期_各商品成交資訊()
Dim xDate(1 To 2) As Date, xPath As String, wB As String
xDate(1) = DateAdd("yyyy", -1, Date) '日期(起):
xDate(2) = Date '日期(迄):
If Time < #3:00:00 PM# Then '營時間業結束之前待大盤資料整理完畢
Do While Weekday(xDate(2), vbMonday) >= 6 Or Weekday(xDate(2), vbMonday) = 1
'排除 週六,週日,週一
xDate(2) = xDate(2) - 1 '向前減一日
Loop
ElseIf Time < #3:00:00 PM# Then ''當日大盤資料整理完畢
Do While Weekday(xDate(2), vbMonday) >= 6 '排除 週六,週日
xDate(2) = xDate(2) - 1 '向前減一日
Loop
End If
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate "http://www.taifex.com.tw/chinese/3/7_12_6.asp"
Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
'<OPTION value="TX" selected>台股期貨(TX)</OPTION>
'<OPTION value="MTX" >小型台指(MTX)</OPTION>
'<OPTION value="TXO" >台指選擇權(TXO)</OPTION>
'<OPTION value="STF" >股票期貨</OPTION>
'.document.ALL("commodity_idt").Value = "STF" '契約: 股票期貨
With .Document.getElementsByTAGName("INPUT")
.Item("datestart").Value = Format(xDate(1), "YYYY/MM/DD")
.Item("dateend").Value = Format(xDate(2), "YYYY/MM/DD")
.Item("button4").Click
End With
Application.Wait Now + #12:00:02 AM#
Application.SendKeys "%s", True '儲存
Application.Wait Now + #12:00:02 AM# '如VBA執行速度快,可延長秒數
Application.SendKeys "%s", True '另存新檔
Application.Wait Now + #12:00:02 AM#
Application.SendKeys "%O", True ' ***開啟檔案***
.Quit '關閉網頁
End With
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)