2015-04-12 107 views
0

我對編寫VBA宏相對比較陌生。我寫了一個簡單的宏來從網站搜索中抓取數據。我希望根據單元格「sheet1」中的單元格內容循環搜索。搜索運行良好,但似乎沒有使用單元格內容。我不知道我需要做些什麼才能正常工作。您的幫助將不勝感激Excel VBA:在網頁搜索中使用單元格內容

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 
+1

嘗試改變'字符串 「網址; HTTP://www.trademe.co.nz/browse/categoryattributesearchresults.aspx MYSEARCH」'到'「URL; http://www.trademe.co.nz/browse/categoryattributesearchresults.aspx?」 &MySearch' –

回答

0

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 
'                  ^^^^^^^^^^^^ 
相關問題