- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
8#
發表於 2014-1-4 14:57
| 只看該作者
回復 6# tsuneng - Option Explicit
- Sub Ex()
- Dim Theurl As String, Sdate
- Theurl = "http://www.otc.org.tw/ch/stock/margin_trading/margin_balance/margin_bal_download.php?d=" & Sdate & "&s=0"
- With ActiveSheet.QueryTables.Add(Connection:="URL;" & Theurl, Destination:=Range("b1"))
- .BackgroundQuery = True
- .RefreshStyle = xlOverwriteCells
- .RefreshPeriod = 0
- .AdjustColumnWidth = False
- .WebSelectionType = xlSpecifiedTables
- .WebFormatting = xlWebFormattingNone
- '.WebTables = "1,2,3,4"
- .WebDisableDateRecognition = True '關閉日期辨識
- .Refresh BackgroundQuery:=False
- .ResultRange.Columns(1).TextToColumns Destination:=.ResultRange.Cells(1), DataType:=xlDelimited, _
- TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
- Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
- :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
- Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1 _
- ), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array _
- (20, 1)), TrailingMinusNumbers:=True
- 'TextToColumns 方法 (資料剖析)的參數可錄製得到
- 'ResultRange.Columns(1):weby資料的第一欄
- 'ResultRange.Cells(1) :weby資料的第一個Cells(儲存格)
- .Delete
- End With
- End Sub
- Sub Ex1()
- Dim Theurl As String, Sdate, AR
- Sdate = "103/01/03"
- Theurl = "http://www.otc.org.tw/ch/stock/margin_trading/margin_balance/margin_bal_download.php?d=" & Sdate & "&s=0"
- With Workbooks.Open(Theurl)
- AR = .Sheets(1).UsedRange
- .Close False
- End With
- With ActiveSheet
- .UsedRange.Clear
- .Range("A1").Resize(UBound(AR, 1), UBound(AR, 2)) = AR
-
- End With
- End Sub
複製代碼 |
|