how to use .getelementbyID and copy inner html - VBA

六眼飞鱼酱① 提交于 2019-12-12 02:42:48

问题


So I have set up my references to Microsoft HTML Object Library and Microsoft Internet controls, and an example to input a value by getting an element id is below:

With HTMLDoc

.getElementById("USER").setAttribute "value", "myuser"
.getElementById("PASSWORD").setAttribute "value", "mypass"
.getElementById("Button").Click

End With

What Im curious to know, is, lets say there was an ID tag named "ReturnValue" that contained a string in the inner html that I wanted to copy to clipboard, how would I use .getElementByID and COPY in that instance?


回答1:


You can get the innerHTML like this:

TxtHtml = .getElementById("elementId").InnerHtml

You can then set the clipboard text from VBA: http://word.mvps.org/faqs/macrosvba/ManipulateClipboard.htm




回答2:


Use JQuery to access innerHtml or Html whatever you want.

var textToCopy = $(#ReturnValue).innerHtml();

For copying text to clipboard, you can refer Copy / Put text on the clipboard with FireFox, Safari and Chrome



来源:https://stackoverflow.com/questions/12344559/how-to-use-getelementbyid-and-copy-inner-html-vba

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