返回列表 上一主題 發帖

設迴圈

你的程式碼是不是沒有複製完整  怎麼會沒有第一行 "sub"
大家互相幫忙解決問題,才會進步

TOP

回復 1# 518587
  1. Sub test1()

  2.     Dim a As String           '設定a變數為字串
  3.     Dim i As Integer          '跑迴圈
  4.    
  5.     For i = 2 To 6            '跑回圈  因為你有五個網址   所以是從2跑到6 五次

  6.         a = Worksheets("工作表2").Range("B" & i)   'i=2 是B2  以此類推 B3   B4   B5   B6
  7.         
  8.         With ActiveSheet.QueryTables.Add(Connection:= _
  9.             "URL;http://www.atpworldtour.com/Tennis/Players/Ac/R/Ricardo-Acioly.aspx", _
  10.             Destination:=Range("$A$1"))   '以下網址是你提供  就不解說
  11.             .Name = "Ricardo-Acioly"
  12.             .FieldNames = True
  13.             .RowNumbers = False
  14.             .FillAdjacentFormulas = False
  15.             .PreserveFormatting = True
  16.             .RefreshOnFileOpen = False
  17.             .BackgroundQuery = True
  18.             .RefreshStyle = xlInsertDeleteCells
  19.             .SavePassword = False
  20.             .SaveData = True
  21.             .AdjustColumnWidth = True
  22.             .RefreshPeriod = 0
  23.             .WebSelectionType = xlEntirePage
  24.             .WebFormatting = xlWebFormattingNone
  25.             .WebPreFormattedTextToColumns = True
  26.             .WebConsecutiveDelimitersAsOne = True
  27.             .WebSingleBlockTextImport = False
  28.             .WebDisableDateRecognition = False
  29.             .WebDisableRedirections = False
  30.             .Refresh BackgroundQuery:=False
  31.         End With
  32.     Next i
  33. End Sub
複製代碼
迴圈1test.rar (15.56 KB)
大家互相幫忙解決問題,才會進步

TOP

        靜思自在 : 不要小看自己,因為人有無限的可能。
返回列表 上一主題