简体   繁体   English

URL中的Excel VBA变量

[英]Excel VBA Variable in URL

I would like to include a variable in a Google search URL. 我想在Google搜索网址中包含一个变量。 The URL, at present is: 该URL当前为:

IE.Navigate " https://www.google.com/search?q= DNR-12-1G +$+Price" IE.Navigate“ https://www.google.com/search?q= DNR-12-1G + $ + Price”

How would I replace the emboldened URL text with a defined string variable such as "pn"? 如何用定义的字符串变量(例如“ pn”)替换加粗的URL文本? Thanks 谢谢

To use a variable all you need is to substitute the text with it 要使用变量,您所需要做的就是用它替换文本

IE.Navigate "https://www.google.com/search?q=" & pn & "+$+Price" 

That would do the job. 这样就可以了。 If you wanted to use the content of a cell, either set pn to the cell value like this: 如果要使用单元格的内容,可以将pn设置为如下所示的单元格值:

pn = ThisWorkbook.Worksheets(1).Range("A1").Value

Adjust as necessary for your worksheet and cell address... or refer to it directly in the Navigate step: 根据需要调整工作表和单元格地址...,或在“ Navigate步骤中直接引用它:

IE.Navigate "https://www.google.com/search?q=" & ThisWorkbook.Worksheets(1).Range("A1").Value & "+$+Price" 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM