2017-02-04 103 views
0

我试图下载马匹的数据表。用列中的值替换部分URL

宏中唯一的变量是URL的一部分。

我有列在“A”列出的所有变量(马编号)。

我想使用从网站收集的信息创建一个新工作表,然后使用列“A”中下一行的数字(新变量)再次收集信息。

到目前为止,这是我的代码:

Sub Makro1() 
' 
' Makro1 Makro 
' 
Dim nummer As String 

nummer = Sheets("Ark1").Range("A1:A10") 

' 
    ActiveWorkbook.Worksheets.Add 
    With ActiveSheet.QueryTables.Add(Connection:= _ 
     "URL;http://195.198.34.45/trav/hast/visa/" & nummer & "/resultat", Destination:=Range _ 
     ("$A$1")) 
     .CommandType = 0 
     .Name = "resultat" 
     .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 = True 
     .WebDisableRedirections = False 
     .Refresh BackgroundQuery:=False 
    End With 
    Columns("D:D").Select 
    ActiveWindow.SmallScroll Down:=21 
    Columns("E:E").Select 
    Range("E22").Activate 
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove 
    Columns("D:D").Select 
    Range("D22").Activate 
    Selection.TextToColumns Destination:=Range("D1"), DataType:=xlDelimited, _ 
     TextQualifier:=xlNone, ConsecutiveDelimiter:=False, Tab:=True, Semicolon _ 
     :=False, Comma:=False, Space:=False, Other:=True, OtherChar:="/", _ 
     FieldInfo:=Array(1, 2), TrailingMinusNumbers:=True 
End Sub 

User sheet trying to describe problem

+0

我和你在一起,直到“然后在coulmn的下一行做”A“” - 你究竟是什么意思? – TheSilkCode

+0

我想我试图创建一个多重查询。 多重查询的所有变量均以coulmn列出A –

回答

0

如何处理多个查询,不知道你想和每一个结果

Sub Makro1() 
' 
' Makro1 Makro 
' 
    Set ws = ActiveSheet 'sheet containing your numbers in column A 
    ActiveWorkbook.Worksheets.Add 
    For Each nummer In ws.Range("A1:A10") 
    If nummer.Text = "" Then Exit For 
     For Each qt In ActiveSheet.QueryTables 
      qt.Delete 
     Next 
     With ActiveSheet.QueryTables.Add(Connection:= _ 
      "URL;http://195.198.34.45/trav/hast/visa/" & nummer.Text & "/resultat", Destination:=Range("$A$1")) 
      .Name = "resultat" 
      .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 = True 
      .WebDisableRedirections = False 
      .Refresh BackgroundQuery:=False 
      nummer.Offset(0, 1) = ActiveSheet.Cells(21, 1) 
     End With 
    Next 
    Application.DisplayAlerts = False 
    ActiveSheet.Delete 
    Application.DisplayAlerts = True 
End Sub 
做一个命题
+0

感谢您的帮助。 有一个问题,与第二和第三查询我想.. 从我的理解这一点: 'Set WS = ActiveSheet' 意味着它将使用活动板在接下来的查询,但我想它使用我的“主”表的下一行中的数字。 –

+0

我试图添加一些到我原来的文章,并添加了一张图片。 我会稍后使用收集的数据进行进一步处理 谢谢 –

+0

我已编辑代码,将名称发现旁边的号码 – h2so4