我对编写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
答案 0 :(得分:0)
MySearch
是一个包含某个字符串的变量,但是在这里你把它视为实际的文字文本“MySearch”,这意味着你正在搜索“MySearch”这个词,这显然不是你想要的。
"URL;http://www.trademe.co.nz/browse/categoryattributesearchresults.aspx?MySearch"
' ^^^^^^^^
要正确连接字符串,您需要将其更改为
"URL;http://www.trademe.co.nz/browse/categoryattributesearchresults.aspx?" & MySearch
' ^^^^^^^^^^^^