Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 使用循环将Web中的数据转换为行_Vba_Excel_Web Scraping_Transpose - Fatal编程技术网

Vba 使用循环将Web中的数据转换为行

Vba 使用循环将Web中的数据转换为行,vba,excel,web-scraping,transpose,Vba,Excel,Web Scraping,Transpose,我正试图用我相当基本的excel技能来获取大量数据。我将此用作指南(),并已使其适用于我的数据,但现在尝试修改代码以满足我的要求 我在各栏中列出了大约10000个卷号,需要从该站点中获取数据(最后10位是卷号): 基本上,我希望保留母版页上的所有新数据,而不是为每个页面下载添加新的工作表(根据我在上面使用的指南),只需将其转换为具有相应卷号的行(可能来自C列) 我的代码如下: Sub adds() For x = 1 To 5 Worksheets("RollNo").Select Worksh

我正试图用我相当基本的excel技能来获取大量数据。我将此用作指南(),并已使其适用于我的数据,但现在尝试修改代码以满足我的要求

我在各栏中列出了大约10000个卷号,需要从该站点中获取数据(最后10位是卷号):

基本上,我希望保留母版页上的所有新数据,而不是为每个页面下载添加新的工作表(根据我在上面使用的指南),只需将其转换为具有相应卷号的行(可能来自C列)

我的代码如下:

Sub adds()
For x = 1 To 5
Worksheets("RollNo").Select
Worksheets("RollNo").Activate
mystr = "URL;http://www.winnipegassessment.com/AsmtPub/english/propertydetails/details.aspx?pgLang=EN&isRealtySearch=true&RollNumber=2000416000.html"
mystr = Cells(x, 1)
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = x
With ActiveSheet.QueryTables.Add(Connection:=mystr, Destination:=Range("$A$2"))
'CommandType = 0
.Name = "2000416000_1"
.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,6,7"  '---> Note: many tables have been selected for import from the website
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Next x
End Sub
subprocessall()
尺寸c作为范围,shtData作为工作表
设置shtData=工作表(“WebQuery”)
对于工作表(“卷号”)范围(“A1:A5”)单元格中的每个c
如果c.值为“”,则
获取数据c.值
'将提取的数据移动到工作表中
用c.EntireRow
.Cells(2).Value=shtData.Range(“A2”).Value
“等等。。。。
以
如果结束
下一个c
端接头
子获取数据(rollNo)
Const BASE_URL As String=“URL;http://www.winnipegassessment.com/AsmtPub/english/" & _
“propertydetails/details.aspx?pgLang=EN&isRealtySearch=true&RollNumber=”
将qt设置为查询表
使用工作表(“WebQuery”)
出错时继续下一步
.QueryTables(1).删除
错误转到0
.细胞,清除
With.QueryTables.Add(连接:=BASE\u URL&rollNo,目的地:=.Range(“A2”))
.Name=“2000416000\u 1”
.FieldNames=True
.rowNumber=False
.FillAdjacentFormulas=False
.PreserveFormatting=True
.refreshinfoleopen=False
.BackgroundQuery=True
.RefreshStyle=xlInsertDeleteCells
.SavePassword=False
.SaveData=True
.AdjustColumnWidth=True
.RefreshPeriod=0
.WebSelectionType=xlSpecifiedTables
.WebFormatting=xlWebFormattingNone
.WebTables=“2,6,7”
.WebPreFormattedTextToColumns=True
.WebConsecutiveDelimiterSong=True
.WebSingleBlockTextImport=False
.WebDisableDateRecognition=False
.WebDisableRedirections=False
.Refresh BackgroundQuery:=False
以
以
端接头

非常感谢您的回复,当我运行时出现以下错误:“运行时错误9:下标超出范围”,在线:Set shtData=Worksheets(“WebQuery”)是否有名为“WebQuery”的工作表?如果没有,那么添加您将需要添加一个(或者将代码中的名称更改为您要使用的现有工作表)Ha-正如您编写的那样解决它。当我运行脚本时,它只是删除B列的内容。。。也许我的主文件设置不正确(我试图添加图片,但网站不允许我)。。。。我的A列由网址组成,例如:url;B列是对应的RollNo(在本例中:2001118000)。。。我是否应该对其进行不同的设置以使其工作?您需要根据您的确切布局调整代码。在我的示例代码中,我将查询表中的第一个单元格复制到B列。如果您想从其他位置开始,请将
.Cells(2)
更改到其他列(当然,您需要添加查询表中的其他值…)
Sub ProcessAll()
    Dim c As Range, shtData As Worksheet

    Set shtData = Worksheets("WebQuery")

    For Each c In Worksheets("RollNo").Range("A1:A5").Cells
        If c.Value <> "" Then
            FetchData c.Value
            'move fetched data to the sheet
            With c.EntireRow
                .Cells(2).Value = shtData.Range("A2").Value
                'etc....
            End With
        End If
    Next c

End Sub

Sub FetchData(rollNo)
Const BASE_URL As String = "URL;http://www.winnipegassessment.com/AsmtPub/english/" & _
           "propertydetails/details.aspx?pgLang=EN&isRealtySearch=true&RollNumber="
Dim qt As QueryTable

    With Worksheets("WebQuery")
        On Error Resume Next
        .QueryTables(1).Delete
        On Error GoTo 0
        .Cells.Clear
        With .QueryTables.Add(Connection:=BASE_URL & rollNo, Destination:=.Range("A2"))
            .Name = "2000416000_1"
            .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,6,7"
            .WebPreFormattedTextToColumns = True
            .WebConsecutiveDelimitersAsOne = True
            .WebSingleBlockTextImport = False
            .WebDisableDateRecognition = False
            .WebDisableRedirections = False
            .Refresh BackgroundQuery:=False
        End With
    End With

End Sub