Copy Text from Range in Excel into Word Document

后端 未结 2 568
耶瑟儿~
耶瑟儿~ 2020-12-11 12:21

how do you:

1) copy text from a range in an Excel Document.
2) Open a Word Document.
3) inserts the text into a specific part of the word document.

2条回答
  •  一向
    一向 (楼主)
    2020-12-11 13:16

    Here's some code I wrote for replacing bookmark text in Word

    Sub FillBookmark(ByRef wdDoc As Object, _
        ByVal vValue As Variant, _
        ByVal sBmName As String, _
        Optional sFormat As String)
    
        Dim wdRng As Object
    
        'store the bookmarks range
        Set wdRng = wdDoc.Bookmarks(sBmName).Range
    
        'if the optional format wasn’t supplied
        If Len(sFormat) = 0 Then
            'replace the bookmark text
            wdRng.Text = vValue
        Else
            'replace the bookmark text with formatted text
            wdRng.Text = Format(vValue, sFormat)
        End If
    
        're-add the bookmark because the above destroyed it
        wdRng.Bookmarks.Add sBmName, wdRng
    
    End Sub
    

    More details here

    http://www.dailydoseofexcel.com/archives/2004/08/13/automating-word/

提交回复
热议问题