1
votes

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.

regards

Kojo

Edit: here is the approach

Dim wrdApp As Word.Application 
Dim wrdDoc As Word.Document 
Dim j As Integer 
Set wrdApp = CreateObject("Word.Application") 
wrdApp.Visible = True 
Set wrdDoc = wrdApp.Documents.Open("C:\Files\DailyStrategy.doc") 

With wrdDoc 
   If wrdDoc.Bookmarks.Exists("MarketCommentry") 
      Then wrdDoc.Bookmarks("MarketCommentry").Range.Text = shortString 
      wrdDoc.SaveAs "c:\temp\test.doc" 
   End If 
   ' close the document 
   Set wrdDoc = Nothing 
   Set wrdApp = Nothing 
End With
2

2 Answers

0
votes

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/