问题
I am feeding Data on website using VBA. I am want to change/replace or update the value of "Style" attribute on that website. HTML
<div class="timeline-row-item style="left: 556px;"></div>
I want to change the value from style="left: 556px;" to style="left: 300px;"
Sub test1()
Dim IE As New SHDocVw.InternetExplorer
IE.document.querySelectorAll("div[class*= timeline-row-iteml]").setAttribute ("style", left: 300px;")
How can i do this on Excel VBA.
Thank You
回答1:
querySelectorAll returns a collection. You cannot use setAttribute on that. You need an individual node
IE.document.querySelector("div[class*= timeline-row-iteml]").setAttribute("style", "left: 300px;")
Not sure if brackets are needed.
You can also use javascript
IE.document.parentWindow.execScript "document.querySelector('div[class*= timeline-row-iteml]').setAttribute('style', 'left: 300px;');"
If you want to do all matches then you will need to loop the returned nodeList
Dim elems As Object, i As Long
Set elems = IE.document.querySelectorAll("div[class*= timeline-row-iteml]")
For i = 0 To elems.Length -1
elem.item(i).setAttribute('style', 'left: 300px;');"
Next
来源:https://stackoverflow.com/questions/55396709/how-to-replace-or-update-style-attribute-value-by-using-vba