- 帖子
- 2
- 主題
- 1
- 精華
- 0
- 積分
- 3
- 點名
- 0
- 作業系統
- Win 7
- 軟體版本
- 1.0
- 閱讀權限
- 10
- 註冊時間
- 2014-1-13
- 最後登錄
- 2014-1-13
|
[發問] 資料抓取另存在不同sheet, 出現錯誤1004
各位前輩好
我是新手,在練習時碰到以下問題
CommandButton1設定在sheet1
想讓資料存取放在sheet2
所以我的步驟如下
1. click CommandButton1
2. 選取Sheet2,並清除舊有資料
3. 進入外部連結匯入資料,存放在Sheet2的A1儲存格
但執行時卻顯示
執行階段錯誤'1004':
應用程式或物件定義上的錯誤
請問以下程式應該如何修改?
多謝指教
Private Sub CommandButton1_Click()
Sheets("Sheet2").Select
Columns("A:AC").Select
Selection.ClearContents
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://mops.twse.com.tw/mops/web/ajax_t51sb01?step=1&firstin=1&TYPEK=sii" _
, Destination:=Range("$A$1"))
.Name = "ajax_t51sb01?step=1&firstin=1&TYPEK=sii"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Columns("C:AB").Select
Selection.Delete Shift:=xlToLeft
Rows("1:1").Select
Selection.Delete Shift:=xlUp
End Sub |
|