2014-09-03 114 views
0

如果我使用的參數爲變量的話,我會得到輸出無法提取使用ActiveSheet.QueryTables.Add()

的WebContent

「響應」:「錯誤」,「錯誤」:「電影未找到」

fname = Range("B1").Value 
fyear = Range("C1").Value 

With ActiveSheet.QueryTables.Add(Connection:= _ 
    "URL;http://www.omdbapi.com/?t=fname&y=fyear", _ 
    Destination:=Range("B1")) 

如果我用這個:

With ActiveSheet.QueryTables.Add(Connection:= _ 
    "URL;http://www.omdbapi.com/?t=Jaws: The Revenge&y=1987", _ 
    Destination:=Range("A1")) 

然後它將檢索結果。 我對此感到困惑,請幫助我找出錯誤。

回答

0
With ActiveSheet.QueryTables.Add(Connection:= _"URL;http://www.omdbapi.com/?t=" & fname & "&y=" & fyear, _ Destination:=Range("B1")) 

您可能需要解析fname數據以替換URL中無效的空格和其他字符。

+0

我用Trim(fname)去除空白。但是,哪個喧鬧的工作我可以知道任何其他解析方法嗎? – 2014-09-03 12:07:15

+0

實際空間將被%20替換 – Rory 2014-09-03 12:11:36

+0

現在它的工作。感謝幫助。 – 2014-09-03 12:17:17