vba 更改 Excel Web 查询的 URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6115223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
changing a URL for Excel Web Query
提问by Jimmy D
I have an Excel 2010 spreadsheet that gets information from a data connection. On the properties of the connection is the "connection string" which is a URL with several parameters that are passed to the server in the query string. If you click "edit query" you can change the URL and then import new data based on the new URL. I need to do this via VBA.
我有一个 Excel 2010 电子表格,可以从数据连接中获取信息。连接的属性是“连接字符串”,它是一个带有多个参数的 URL,这些参数在查询字符串中传递给服务器。如果单击“编辑查询”,您可以更改 URL,然后根据新 URL 导入新数据。我需要通过 VBA 来做到这一点。
Let's say the connection string is currently http://myserver.com?name=foo
I need to change that to http://myserver.com?name=bar
假设连接字符串目前http://myserver.com?name=foo
我需要将其更改为http://myserver.com?name=bar
How can this be done?
如何才能做到这一点?
回答by Tim Williams
With ActiveSheet.QueryTables(1)
.Connection = "URL;" & NewURL
.Refresh
End With