how to use .getelementbyID and copy inner html - V

2019-09-06 04:24发布

问题:

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