Excel 无法使用ActiveSheet.QueryTables.Add()获取WebContent

Excel 无法使用ActiveSheet.QueryTables.Add()获取WebContent,excel,vba,Excel,Vba,如果我使用参数作为变量,那么我将得到输出 “响应”:“错误”,“错误”:“未找到电影” i、 e 如果我使用这个: With ActiveSheet.QueryTables.Add(Connection:= _ "URL;http://www.omdbapi.com/?t=Jaws: The Revenge&y=1987", _ Destination:=Range("A1")) 然后它将检索结果。 我对此感到困惑,请帮我找出错误 With ActiveSheet.Qu

如果我使用参数作为变量,那么我将得到输出

“响应”:“错误”,“错误”:“未找到电影”

i、 e

如果我使用这个:

With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;http://www.omdbapi.com/?t=Jaws: The Revenge&y=1987", _
    Destination:=Range("A1"))
然后它将检索结果。 我对此感到困惑,请帮我找出错误

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

您可能需要解析fname数据以替换URL中无效的空格和其他字符。

我使用Trim(fname)删除了空格。但哪种噪音有效。我可以知道其他解析方法吗?实际的空格将替换为%20
With ActiveSheet.QueryTables.Add(Connection:= _"URL;http://www.omdbapi.com/?t=" & fname & "&y=" & fyear, _ Destination:=Range("B1"))