View Single Post
 
Old 06-15-2018, 01:10 PM
d4okeefe d4okeefe is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Apr 2013
Posts: 77
d4okeefe is on a distinguished road
Default

I was thinking more like this.

Code:
Sub CopyAndPaste()
    Dim myfile, wdApp As New Word.Application, wdDoc As Word.Document
    myfile = Application.GetOpenFilename(, , "Browse for Document")
    Dim i As Integer
    i = Application.Match("Avg", Sheet1.Range("A1:A20"), 0)
    Range("E" & i).Select
    Selection.Copy
 
    wdApp.Visible = True
    Set wdDoc = wdApp.Documents.Open(myfile)
    'select the word range you want to paste into
    If Range("c2") = 22 Then wdDoc.Bookmarks("d22").Select
    If Range("c2") = 5 Then wdDoc.Bookmarks("d5").Select
    If Range("c2") = -20 Then wdDoc.Bookmarks("d20").Select
    
    'and paste the clipboard contents
    wdApp.Selection.Collapse wdCollapseEnd
    wdApp.Selection.Paste
End Sub
You don't need the range object that I mentioned earlier. You could use it to change the beginning and end of the bookmark, but that seems needlessly complicated now.
Reply With Quote