如何将剪贴板内容粘贴到单词表中的特定位置
问题描述:
作为提取数据表单网络的一部分,我使用以下(有问题的)代码。如何将剪贴板内容粘贴到单词表中的特定位置
Sub USPTOAbstHTML1()
Application.ScreenUpdating = False
Dim Rng As Range, Tbl As table, StrTxt As String, HttpReq As Object, i As Long, oHtml As MSHTML.HTMLDocument, IE As SHDocVw.InternetExplorer
Set HttpReq = CreateObject("Microsoft.XMLHTTP")
Set oHtml = New HTMLDocument
Set IE = CreateObject("InternetExplorer.Application")
With ActiveDocument.Range
For Each Tbl In .Tables
With Tbl
For i = 1 To .Rows.Count
With .Cell(i, 2).Range
If .Hyperlinks.Count > 0 Then
MsgBox .Hyperlinks(1).Address
HttpReq.Open "GET", .Hyperlinks(1).Address, False
HttpReq.send
oHtml.body.innerHTML = HttpReq.responseText
MsgBox HttpReq.responseText
StrTxt = oHtml.getElementsByClassName("claim").Item.innerHTML
With IE
.Visible = False
.navigate "about:blank"
.Document.body.innerHTML = StrTxt
.Document.execCommand "SelectAll"
.Document.execCommand "Copy"
End With
With Tbl.Cell(i, 5).Range
Selection.PasteAndFormat (wdPasteDefault)
End With
End If
.Collapse wdCollapseEnd
.Find.Execute
End With
Next
End With
Next
End With
Set HttpReq = Nothing
Application.ScreenUpdating = True
End Sub
在上面的代码中的问题是,我无法找到由我可以添加剪贴板内容到特定位置即Tbl.Cell任何方法(I,5).Range 该代码是插入数据无论选择。
我试过MSForms.DataObject,但我只能找到只有文本的例子,而我的剪贴板内容不仅仅是文本。 (带图像的格式文本)
有没有其他办法可以完成工作?
答
Range对象也有Paste,PasteFormat和类似的方法。您可能首先需要折叠范围,以使其位于单元格内(而不是包含单元格)。例如:
Set rng = Tbl.Cell(i, 5).Range
rng.Collapse wdCollapseStart
rng.PasteAndFormat wdPasteDefault
完美的作品。感谢您的快速回复。 – Rahul