- 帖子
- 96
- 主題
- 18
- 精華
- 0
- 積分
- 125
- 點名
- 0
- 作業系統
- Windows 7
- 軟體版本
- Office 2007
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2014-3-23
- 最後登錄
- 2022-8-2
|
本帖最後由 smart3135 於 2017-2-25 06:45 編輯
想請教一下各位前輩,以下的程式碼在寫好當天原本可以正常抓到輸入日期的資料
在程式碼完全沒有變更的情況下,隔天執行時輸入較舊的日期卻只能抓到最新當天的資料
有時甚至還抓不到資料,不知道是我電腦EXCEL版本的問題還是程式碼有問題?可以請高手們幫忙看一下嗎?
非常感謝[attach]26720[/attach]- Option Explicit
- Sub 上市外資和投信()
- Dim X, Y, qdate, select2 As String
- Sheets("資料區").Select
- X = InputBox("請輸入月份")
- Y = InputBox("請輸入日期")
- qdate = "106" & "/" & X & "/" & Y
- select2 = "ALLBUT0999"
- With ActiveSheet.QueryTables.Add(Connection:= _
- "URL;http://www.twse.com.tw/ch/trading/fund/T86/T86.php", Destination:=Range( _
- "$A$1"))
- .Name = "證交所三大法人買賣超日報"
- .FieldNames = True
- .RowNumbers = False
- .FillAdjacentFormulas = False
- .PreserveFormatting = False
- .RefreshOnFileOpen = False
- .BackgroundQuery = False
- .RefreshStyle = xlOverwriteCells
- .AdjustColumnWidth = False
- .WebSelectionType = xlSpecifiedTables
- .WebFormatting = xlWebFormattingNone
- .WebTables = "2"
- .PostText = "qdate=" & qdate & "&select2=" & select2
- .WebPreFormattedTextToColumns = True
- .WebConsecutiveDelimitersAsOne = True
- .WebSingleBlockTextImport = False
- .WebDisableDateRecognition = True
- .WebDisableRedirections = False
- .Refresh BackgroundQuery:=False
- End With
- End Sub
- Sub 上櫃外資買賣超()
- '上櫃外資買賣超
- Dim X, Y, mydate As String
- X = InputBox("請輸入月份")
- Y = InputBox("請輸入日期")
- mydate = "106" & "/" & X & "/" & Y
- Sheets("資料區").Select
- With ActiveSheet
- .Cells.Clear
- With .QueryTables.Add(Connection:= _
- "TEXT;http://www.tpex.org.tw/web/stock/3insti/qfii_trading/forgtr_download.php?l=zh-tw&t=D&type=buy&d=mydate&s=0,asc,1" _
- , Destination:=.Range("$A$1"))
- .TextFileCommaDelimiter = True
- .Refresh BackgroundQuery:=False
- .Delete
- End With
- End With
- End Sub
- Sub 上櫃投信買賣超()
- '上櫃投信買賣超
- Dim X, Y, mydate As String
- X = InputBox("請輸入月份")
- Y = InputBox("請輸入日期")
- mydate = "106" + "/" + "X" + "/" + "Y"
- Sheets("資料區").Select
- Range("a1").Select
- With ActiveSheet
- .Cells.Clear
- With .QueryTables.Add(Connection:= _
- "TEXT;http://www.tpex.org.tw/web/stock/3insti/sitc_trading/sitctr_download.php?l=zh-tw&t=D&type=buy&d=mydate&s=0,asc,1" _
- , Destination:=.Range("$A$1"))
- .TextFileCommaDelimiter = True
- .Refresh BackgroundQuery:=False
- .Delete
- End With
- End With
- End Sub
複製代碼 |
-
-
TEST.zip
(19.74 KB)
|