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

Sorry, I think I made that confusing. There's no need for the for loop in your code.
Do something 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
         Selection.Collapse wdCollapseEnd
         Selection.Paste
    End If
    If Range("c2") = 5 Then
         wdDoc.Bookmarks("d5").Select
         Selection.Collapse wdCollapseEnd
         Selection.Paste
    End If
    If Range("c2") = -20 Then 
         wdDoc.Bookmarks("d20").Select
         Selection.Collapse wdCollapseEnd
         Selection.Paste
    End If
End Sub
Reply With Quote