2015-12-02 87 views
0

作爲提取數據表單網絡的一部分,我使用以下(有問題的)代碼。如何將剪貼板內容粘貼到單詞表中的特定位置

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,但我只能找到只有文本的例子,而我的剪貼板內容不僅僅是文本。 (帶圖像的格式文本)

有沒有其他辦法可以完成工作?

回答

0

Range對象也有Paste,PasteFormat和類似的方法。您可能首先需要摺疊範圍,以使其位於單元格內(而不是包含單元格)。例如:

Set rng = Tbl.Cell(i, 5).Range 
rng.Collapse wdCollapseStart 
rng.PasteAndFormat wdPasteDefault 
+0

完美的作品。感謝您的快速回復。 – Rahul

相關問題