简体   繁体   English

如何通过vba将HTML span属性复制到excel

[英]How to copy HTML span attribute to excel by vba

I am trying to copy web span value to excel sheet by excel vba.我正在尝试通过 excel vba 将 web 跨度值复制到 excel 表中。 I try copy from input box which same value with span but it's unable to copy / null value.我尝试从输入框中复制与跨度相同的值,但无法复制/空值。 This HTML to copy这个要复制的 HTML

<td nowrap class="iddisplay"><span style="font-size: 14px" tabIndex="0">IAR/19326/8JM3Z</span>
<input type="hidden" name="transactionId" id="transactionId" value="IAR193268JM3Z"></td>

so i want to copy value IAR/19326/8JM3Z from span or IAR193268JM3Z from transactionId value The excel vba code that i use所以我想从 span 中复制值 IAR/19326/8JM3Z 或从 transactionId 值中复制 IAR193268JM3Z 我使用的 excel vba 代码

Set str_val12 = IE.document.getElementById("transactionId")

clip.SetText str_val12.innerText
'clip.SetText str_val12.value
clip.PutInClipboard
test.Cells(i + 2, 6).Select
test.Cells(i + 2, 6).PasteSpecial "Unicode Text"

Thanks谢谢

如果 css 类iddisplay仅用于该特定 td 标签:

Cells(i + 2, 6) = IE.document.getElementsByClassName("iddisplay")(0).FirstChild.innertext

I haven't tested this but something along the lines of:我还没有测试过这个,但大致如下:

Dim element as Variant

For Each element in IE.document.getElementsById("transactionId")
    If element.value = "IAR193268JM3Z" Then
        Set str_val12 = element.innerText
        test.cells(i + 2, 6).Value = str_val12
    End If
Next element

Let me know if this throws an error and on which line.让我知道这是否会引发错误以及在哪一行。 I am unsure if .Value is a way to check the value="IAR193268JM3Z" embedded within the input tag, but let's see.我不确定.Value是否是一种检查输入标签中嵌入的value="IAR193268JM3Z" ,但让我们看看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM