Excel VBA Variable in URL

ε祈祈猫儿з 提交于 2021-01-07 08:04:10

问题


I would like to include a variable in a Google search URL. The URL, at present is:

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"? Thanks


回答1:


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 = ThisWorkbook.Worksheets(1).Range("A1").Value

Adjust as necessary for your worksheet and cell address... or refer to it directly in the Navigate step:

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


来源:https://stackoverflow.com/questions/38932749/excel-vba-variable-in-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!