- 帖子
- 13
- 主題
- 3
- 精華
- 0
- 積分
- 23
- 點名
- 0
- 作業系統
- Win 7
- 軟體版本
- Office 2002
- 閱讀權限
- 10
- 註冊時間
- 2012-12-25
- 最後登錄
- 2013-11-6
|
6#
發表於 2013-9-3 01:17
| 只看該作者
我將date的日期改為星期天的日期,程式會無止靜的跑回圈?
請問GBKEE超級版主,假如我更新的日期(Date)距離股市最後交易日超過1天以上,又該如何修改呢?感謝指導- Sub 下載網站資料()
- Dim Startmonth As String, Startday As String, xDate As Date, Msg As Boolean, Sh As Worksheet
- On Error GoTo EX '程式執行中有錯誤時跳到 EX: 繼續執行程式
- xDate = Date '當日
- Set Sh = ActiveSheet '指定工作表:此程式在任何模組中皆可用
- EX:
- If Err.Number <> 0 Or Msg = True Then '當日(尚未有資料:錯誤) 或 休市
- [color=Red]xDate = xDate - 1 (應改為xDate = Date - 1)[/color] 假如休市超過1天以上(2,3,4,5,6,春節9天),又如何修改呢?
- Err.Clear
- Msg = False
- End If
- Sh.UsedRange.Clear '清理工作表已使用的範圍
- Startday = Format(xDate, "YYYYMMDD")
- Startmonth = Format(xDate, "YYYYMM")
- '下載網站的網址
- With Sh.QueryTables.Add(Connection:="URL;http://www.twse.com.tw/ch/trading/exchange/MI_INDEX/genpage/Report" & Startmonth & "/A112" & Startday & "ALLBUT0999_1.php?select2=ALLBUT0999&chk_date=" & Format(xDate, "E/MM/DD"), Destination:=Range("A3"))
- .RefreshStyle = xlOverwriteCells '抓取網頁的第10個表格作為匯入資料
- .WebTables = "10"
- .Refresh BackgroundQuery:=False '當日(尚未有資料:錯誤)
- If Application.CountA(Sh.QueryTables(1).ResultRange) = 0 Then '休市 沒有資料
- Msg = True
- GoTo EX
- End If
- End With
- With Sh.UsedRange
- .Font.Size = 12
- .EntireColumn.AutoFit
- End With
- End Sub
複製代碼 回復 5# GBKEE |
|