QueryTables重複查詢,如何覆蓋上一筆查詢
- 帖子
- 16
- 主題
- 10
- 精華
- 0
- 積分
- 68
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- 2003
- 閱讀權限
- 20
- 註冊時間
- 2015-2-26
- 最後登錄
- 2021-10-4
|
QueryTables重複查詢,如何覆蓋上一筆查詢
各位大大安安
我使用QueryTable作查詢時,
每次查詢一個股價資料
就會把前一個已經查好的股價資料往旁邊擠
到最後儲存格就會用罄
我希望的是每次查詢都使用同一個範圍的儲存格,
意即把上一個查好的股價資料覆蓋(不要往旁邊擠)
我該怎麼修改呢?
程式碼如下
With ActiveSheet.QueryTables.Add(Connection:="URL;https://tw.finance.yahoo.com/q/q?s=" & stockID, Destination:=Sheets(10).Range("A1"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "6"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
.Name = .ResultRange.Cells(3, 1)
End With |
|
|
|
|
|
|
|
- 帖子
- 16
- 主題
- 10
- 精華
- 0
- 積分
- 68
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- 2003
- 閱讀權限
- 20
- 註冊時間
- 2015-2-26
- 最後登錄
- 2021-10-4
|
4#
發表於 2015-3-19 17:28
| 只看該作者
|
|
|
|
|
|
|
- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
3#
發表於 2015-3-1 08:15
| 只看該作者
回復 1# tsunamix03
在程式碼匯入查詢時,指定這屬性的參數值- .RefreshStyle = xlOverwriteCells
複製代碼 VBA 的說明- RefreshStyle 屬性
- 請參閱套用至範例特定傳回或者設定指定工作表中列的插入或刪除模式,以提供查詢傳回的記錄集的列數。讀/寫 XlCellInsertionMode。
- XlCellInsertionMode 可以是這些 XlCellInsertionMode 常數之一。
- xlInsertDeleteCells。插入或者刪除部份列以適應新記錄集所需要的實際列數。
- xlOverwriteCells。不在工作表中新增新的儲存格或列。如果溢出則取代周圍的儲存格的內容。
- xlInsertEntireRows。新增資料 recordset 中的所有列,並且允許溢出原有區域。工作表中沒有被刪除的儲存格或列。
複製代碼 |
|
|
|
|
|
|
|
暱稱: joey0415
中學生
- 帖子
- 361
- 主題
- 57
- 精華
- 0
- 積分
- 426
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- 2003,2010
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2010-5-13
- 最後登錄
- 2022-12-8
|
2#
發表於 2015-2-26 18:49
| 只看該作者
- Sub ex()
- Range("A:L").Clear
- With ActiveSheet.QueryTables.Add(Connection:="URL;https://tw.finance.yahoo.com/q/q?s=" & 1101, Destination:=Range("A1"))
- .WebSelectionType = xlSpecifiedTables
- .WebFormatting = xlWebFormattingNone
- .WebTables = "6"
- .Refresh BackgroundQuery:=False
- .Delete
- End With
- End Sub
複製代碼 回復 1# tsunamix03 |
|
|
|
|
|
|
|