本文介绍了如何替换或更新“样式"使用VBA获得属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用VBA在网站上提供数据.我想更改/替换或更新该网站上样式"属性的值.HTML
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>
我想从style ="left:556px;"更改值.为style ="left:300px;"
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;")
如何在Excel VBA上执行此操作.
How can i do this on Excel VBA.
谢谢
推荐答案
querySelectorAll返回一个集合.您不能在其上使用setAttribute.您需要一个单独的节点
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;")
不确定是否需要括号.
您也可以使用javascript
You can also use javascript
IE.document.parentWindow.execScript "document.querySelector('div[class*= timeline-row-iteml]').setAttribute('style', 'left: 300px;');"
如果要进行所有匹配,则需要循环返回的nodeList
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
这篇关于如何替换或更新“样式"使用VBA获得属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!