返回列表 上一主題 發帖

抓WEB資料出現「應用程式或物件定義上的錯誤」

抓WEB資料出現「應用程式或物件定義上的錯誤」

[版主管理留言]
  • GBKEE(2016/10/17 09:48): 需附檔,沒人知道錯在哪裡.

Dim xlMonth As String, row As Integer
   
    row = 2              '放置資料的起始列    須更改
    For yr = 92 To 92   '取得的年份歷史資料  視需要更改

        For m = 8 To 12  '取得的月份歷史資料  視需要更改
            xlMonth = Format(m, "00")
            
            
            Sheets(42).Activate
            With ActiveSheet.QueryTables.Add(Connection:="URL;http://siis.twse.com.tw/publish/sii/" & yr & "IRB130_" & xlMonth & ".HTM", Destination:=Sheets(42).Range("o1"))
            '.Name = stockID & "_1"
                .FieldNames = True
                .RowNumbers = False
                .FillAdjacentFormulas = False
                .PreserveFormatting = True
                .RefreshOnFileOpen = False
                .BackgroundQuery = True
                .RefreshStyle = xlOverwriteCells
                .SavePassword = False
                .SaveData = True
                .AdjustColumnWidth = True
                .RefreshPeriod = 0
                .WebSelectionType = xlSpecifiedTables
                .WebFormatting = xlWebFormattingNone
                .WebTables = "2"
                .WebPreFormattedTextToColumns = True
                .WebConsecutiveDelimitersAsOne = True
                .WebSingleBlockTextImport = False
                .WebDisableDateRecognition = False
                .WebDisableRedirections = False
                .Refresh BackgroundQuery:=False
            End With

            
            
            'With ActiveSheet.QueryTables.Add(Connection:= _
            '    "URL;http://siis.twse.com.tw/publish/sii/" & yr & "IRB130_" & xlMonth & ".HTM", Destination:=Range _
            '    ("O1"))
            '    .Name = "92IRB130_08"
            '    .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 = "2"
            '    .WebPreFormattedTextToColumns = True
            '    .WebConsecutiveDelimitersAsOne = True
            '    .WebSingleBlockTextImport = False
            '    .WebDisableDateRecognition = False
            '    .WebDisableRedirections = False
            '    .Refresh BackgroundQuery:=False
            'End With
            
            Cells(row, "B") = Cells(1500, "P")
            Cells(row, "C") = Cells(1500, "S")
            Cells(row, "D") = Cells(1500, "U")
            Cells(row, "E") = Cells(1500, "V")
            Cells(row, "F") = Cells(1500, "W")            
            row = row + 1
   
        Next
    Next

        靜思自在 : 靜坐常恩己過、閒談莫論人非。
返回列表 上一主題