VBA use of a variable in .queryselector

deltamu

New Member
Joined
Jun 14, 2018
Messages
10
Hi,
I have a web page with multiple dynamic hrefs, everyone associated with specific data. I have to click on one of these based on related data.
To do that, I have temporarily exported to excel the href list with related data as a support to choose the correct one.
The website does not accept an external connection request, so I cannot click on the link created in Excel but I do need to click on href from within the web page.
So, I thought to assign the href innerHTML content to a string variable and use it to find and click on the href.
The question is, it is possibile to use variables with queryselector?
This is the relevant piece of code:
VBA Code:
'this is the string where I stored the href content
hrefStr = CStr(ActiveWorkbook.Sheets("temp").Cells(m + 1, 6).Value)

'this doesn't work            
IE.Document.querySelector("a[href=hrefStr").Click

'this doesn't work either
IE.Document.querySelector("a[href=" + (hrefStr) + "]").Click

'this doesn't work either
IE.Document.querySelector("a[href=" & hrefStr & "]").Click

I've found that in javascript it is possibile to do something like this:
var name = "hello, world!";
document.querySelector("[data-name=" + CSS.escape(name) + "]");

but CSS.escape it is not allowed in vba. How can I solve it?

Any suggestion is appreciated.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Watch MrExcel Video

Forum statistics

Threads
1,130,029
Messages
5,639,623
Members
417,101
Latest member
amoverton2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top