返回列表 上一主題 發帖

EXCEL網頁查詢如何避開不存在網頁

回復 1# chwqk
試試看
  1. Sub Macro1()
  2.     On Error Resume Next
  3.     For I = 1 To 12
  4.     If I < 10 Then
  5.     M = "0" & I
  6.     Else: M = I
  7.     End If
  8.     RD = "99" & M
  9.     MsgBox RD
  10.     Sheets("減資查詢").Select
  11.     Range("A1").Select
  12.     With Selection.QueryTable
  13.         .Connection = _
  14.         "URL;http://www.twse.com.tw/docs1/data01/market/public_html/b" & RD & ".txt"
  15.         .WebSelectionType = xlEntirePage
  16.         .WebFormatting = xlWebFormattingNone
  17.         .WebPreFormattedTextToColumns = True
  18.         .WebConsecutiveDelimitersAsOne = True
  19.         .WebSingleBlockTextImport = False
  20.         .WebDisableDateRecognition = False
  21.         .WebDisableRedirections = False
  22.         .Refresh BackgroundQuery:=False
  23.     End With
  24.     If Err > 0 Then
  25.         MsgBox "查不到 " & RD
  26.         Err.Clear
  27.     End If
  28.     Next I
  29. End Sub
複製代碼

TOP

        靜思自在 : 待人退一步,愛人寬一寸,就會活得很快樂。
返回列表 上一主題