如何使用 .getelementbyID 并复制内部 html - VBA

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12344559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 17:39:37  来源:igfitidea点击:

how to use .getelementbyID and copy inner html - VBA

internet-explorervbadomgetelementbyid

提问by Jason Bayldon

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:

因此,我设置了对 Microsoft HTML 对象库和 Microsoft Internet 控件的引用,下面是通过获取元素 ID 来输入值的示例:

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?

我很想知道的是,假设有一个名为“ReturnValue”的 ID 标签,它在我想复制到剪贴板的内部 html 中包含一个字符串,我将如何在该实例中使用 .getElementByID 和 COPY?

回答by Tim Williams

You can get the innerHTML like this:

你可以像这样获得innerHTML:

TxtHtml = .getElementById("elementId").InnerHtml

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

然后,您可以从 VBA 设置剪贴板文本:http: //word.mvps.org/faqs/macrosvba/ManipulateClipboard.htm

回答by Mandar

Use JQuery to access innerHtml or Html whatever you want.

使用 JQuery 访问您想要的 innerHtml 或 Html。

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

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

要将文本复制到剪贴板,您可以参考使用 FireFox、Safari 和 Chrome 在剪贴板上复制/放置文本