Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.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
Excel VBA:在web搜索中使用单元格内容_Excel_Vba - Fatal编程技术网

Excel VBA:在web搜索中使用单元格内容

Excel VBA:在web搜索中使用单元格内容,excel,vba,Excel,Vba,我对编写VBA宏比较陌生。我编写了一个简单的宏来从网站搜索中获取数据。我想根据选项卡“sheet1”中的单元格内容循环搜索。搜索运行正常,但似乎没有使用单元格内容。我不确定我需要做什么才能让它正常工作。谢谢你的帮助 Sub Get_internet_data() For x = 1 To 3 Worksheets("Sheet1").Select Worksheets("Sheet1").Activate MySearch =

我对编写VBA宏比较陌生。我编写了一个简单的宏来从网站搜索中获取数据。我想根据选项卡“sheet1”中的单元格内容循环搜索。搜索运行正常,但似乎没有使用单元格内容。我不确定我需要做什么才能让它正常工作。谢谢你的帮助

  Sub Get_internet_data()
       For x = 1 To 3
        Worksheets("Sheet1").Select
        Worksheets("Sheet1").Activate

        MySearch = "URL;http://www.trademe.co.nz/browse/categoryattributesearchresults.aspx?144=-1&144=-1&search=1&sidebar=1&cid=5000&rptpath=5000-"
    MySearch = Cells(x, 1)

    With ActiveSheet.QueryTables.Add(Connection:="URL;http://www.trademe.co.nz/browse/categoryattributesearchresults.aspx?MySearch", Destination:=Range("$C$6"))
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = False
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = False
    .RefreshPeriod = 0
    .WebSelectionType = xlEntirePage
    .WebFormatting = xlWebFormattingNone
    .WebPreFormattedTextToColumns = True
    .WebConsecutiveDelimitersAsOne = True
    .WebSingleBlockTextImport = False
    .WebDisableDateRecognition = False
    .WebDisableRedirections = False
    .Refresh BackgroundQuery:=False
    End With

    Next x
   End Sub

MySear‌​ch
是一个包含特定字符串的变量,但在这里,您将其视为实际的文字文本“MySearch”,这意味着您正在搜索单词“MySearch”,这显然不是您想要的

"URL;http://www.trademe.co.nz/browse/categoryattributesearchresults.aspx?MySear‌​ch" 
'                                                                        ^^^^^^^^
要正确连接字符串,需要将其更改为

"URL;http://www.trademe.co.nz/browse/categoryattributesearchresults.aspx?" & MySearch
'                                                                        ^^^^^^^^^^^^
尝试更改
“URL;http://www.trademe.co.nz/browse/categoryattributesearchresults.aspx?MySearch“
”URL;http://www.trademe.co.nz/browse/categoryattributesearchresults.aspx?“&MySearch