標題:
[發問]
程式語法有誤
[打印本頁]
作者:
pupai
時間:
2014-12-15 16:52
標題:
程式語法有誤
您好
我插入指定日期後,程式錯誤
請幫忙修改
謝謝!!
Sub 巨集()
Dim Theurl As String, Sdate, AR, A As Date
A = Range("A1").Value
Sdate = Text(A1, "emmdd")
Theurl = "http://www.twse.com.tw/ch/trading/fund/BFI82U/BFI82U_print.php?begin_date="&Sdate&end_date=&report_type=day&language=ch&save=csv"
With Workbooks.Open(Theurl)
AR = .Sheets(1).UsedRange
.Close False
End With
With ActiveSheet
.Range("B2").Resize(UBound(AR, 1), UBound(AR, 2)) = AR
End With
End Sub
複製代碼
作者:
hugh0620
時間:
2014-12-15 18:44
回復
1#
pupai
日期格式 :yyyymmdd
Sdate = Text(A1, "emmdd") 是不識這句有誤呢??
作者:
pupai
時間:
2014-12-15 18:56
回復
2#
hugh0620
我猜
Theurl = "http://www.twse.com.tw/ch/trading/fund/BFI82U/BFI82U_print.php?begin_date="&Sdate&end_date=&report_type=day&language=ch&save=csv"
謝謝
作者:
HSIEN6001
時間:
2014-12-16 12:56
本帖最後由 HSIEN6001 於 2014-12-16 12:58 編輯
回復
3#
pupai
用CSV下載,同
http://forum.twbts.com/thread-13018-1-1.html
#6
(一起下載)
Sub CSV下載()
Dim path As String
path = "C:\"
日期 = "20141215"
Set XML = CreateObject("Microsoft.XMLHTTP")
Set stream = CreateObject("ADODB.stream")
URL = "http://www.taifex.com.tw/chinese/3/7_12_8dl.asp?syear=" & VBA.Left(日期, 4) & "&smonth=" & VBA.Mid(日期, 5, 2) & "&sday=" & _
VBA.Right(日期, 2) & "&eyear=" & VBA.Left(日期, 4) & "&emonth=" & VBA.Mid(日期, 5, 2) & "&eday=" & VBA.Right(日期, 2)
XML.Open "GET", URL, 0
XML.send
With stream
.Type = 1
.Open
.write XML.responseBody
If Dir(path & "類股期貨" & 日期 & ".csv") <> "" Then Kill (path & "類股期貨" & 日期 & ".csv")
.SaveToFile (path & "類股期貨" & 日期 & ".csv")
.Close
End With
URL = "http://www.twse.com.tw/ch/trading/fund/BFI82U/BFI82U_print.php?begin_date=" & _
VBA.Left(日期, 8) & "&end_date=" & VBA.Left(日期, 8) & "&report_type=day&language=ch&save=csv"
XML.Open "GET", URL, 0
XML.send
With stream
.Type = 1
.Open
.write XML.responseBody
If Dir(path & "三大法人買賣超" & 日期 & ".csv") <> "" Then Kill (path & "三大法人買賣超" & 日期 & ".csv")
.SaveToFile (path & "三大法人買賣超" & 日期 & ".csv")
.Close
End With
End Sub
複製代碼
作者:
pupai
時間:
2014-12-16 14:13
回復
4#
HSIEN6001
感謝回復
後來我用土方法
Sub 巨集()
Dim Theurl As String, Sdate, AR, A As Date
A = Range("A1").Value
Sdate = Format(A, "yyyymmdd")
Theurl = "http://www.twse.com.tw/ch/trading/fund/BFI82U/BFI82U_print.php?begin_date=" & Sdate & "&end_date=" & Date & "&report_type=day&language=ch&save=csv"
With Workbooks.Open(Theurl)
AR = .Sheets(1).UsedRange
.Close False
End With
With ActiveSheet
.Range("B2").Resize(UBound(AR, 1), UBound(AR, 2)) = AR
End With
End Sub
複製代碼
作者:
HSIEN6001
時間:
2014-12-16 20:19
回復
5#
pupai
可能是這個問題 path = "C:\"
這是指定存 C:\
如果你沒有直接權限 , 自己建立一個資料夾
改成為你使用者可存檔的位置
作者:
GBKEE
時間:
2014-12-17 07:45
回復
3#
pupai
Sub 巨集()
Dim Theurl As String, Sdate, AR, A As Date
A = Range("A1").Value
Sdate = Format(A, "yyyymmdd")
Theurl = "http://www.twse.com.tw/ch/trading/fund/BFI82U/BFI82U_print.php?begin_date=" & Sdate & "&end_date=&report_type=day&language=ch&save=csv"
With Workbooks.Open(Theurl)
AR = .Sheets(1).UsedRange
.Close False
End With
With ActiveSheet
.Range("B2").Resize(UBound(AR, 1), UBound(AR, 2)) = AR
End With
End Sub
複製代碼
作者:
pupai
時間:
2014-12-17 10:52
回復
7#
GBKEE
謝謝 回復
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)