標題:
[發問]
外部資料匯入問題
[打印本頁]
作者:
power82843
時間:
2016-11-28 22:41
標題:
外部資料匯入問題
各位前輩大家好,
我最近開始學VBA有許多問題,可能有很多問題太基本還請各位多多海涵,也請不吝給予建議,謝謝!
以下是目前遇到的問題,我將Web表格匯入A sheet,再將A sheet 中的"股東權益報酬率"複製到B sheet,可是每次大約跑80筆資料後就會卡住,強制停止程式再重新啟動會顯示 .Refresh BackgroundQuery:=False 這一行錯誤,但關掉Excel 再重新開始就可以繼續跑,在論壇中好像有看到類似問題但還是解不出來,還請各位前輩幫忙看我的問題是出在哪,感謝!
For i = 281 To Sheets("個股資料").Range("B281").End(xlDown).Row
Worksheets("ROE總表").Range("B1").Value = "++++++++++++++++++++++++++++++++++++++++++++++++++++"
Worksheets("ROE").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://stockchannelnew.sinotrade.com.tw/z/zc/zcr/zcra/zcra_" & Sheets("個股資料").Range("B" & i) & ".djhtm", Destination:=Range("B1"))
.Name = "0000000"
.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 = "1"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Range("C1:C500").Find("股東權益報酬率").Select
Range(Selection, Selection.End(xlToRight)).Copy
Worksheets("ROE總表").Select
Worksheets("ROE總表").Range("B1").Select
ActiveCell.End(xlDown).Select
lastrow = ActiveCell.Row
ActiveSheet.Paste Destination:=Worksheets("ROE總表").Range("b" & lastrow + 1)
Worksheets("ROE總表").Range("A" & lastrow + 1).Value = Worksheets("個股資料").Range("C" & i).Value
Worksheets("ROE").Select
Worksheets("ROE").Range("B1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Delete
Next
End Sub[/code]
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)