
06-18-2018, 12:19 PM
|
Advanced Beginner
|
|
Join Date: Jun 2018
Posts: 31
|
|
Quote:
Originally Posted by d4okeefe
There's a lot going on in your original code, so I'll do my best. I can't recreate it perfectly without the original files. Here goes:
Code:
Sub test_ok()
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
Dim excel_selection As String
excel_selection = Selection.Text
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open(myfile)
'select the word range you want to paste into
Dim bk As Bookmark, bk_new As Bookmark
Dim new_range As Range
Dim bk_name As String
If Range("c2") = 22 Then
Set bk = wdDoc.Bookmarks("d22")
bk_name = bk.Name
Set new_range = wdDoc.Range(bk.Start, bk.End)
End If
If Range("c2") = 5 Then
Set bk = wdDoc.Bookmarks("d5")
bk_name = bk.Name
Set new_range = wdDoc.Range(bk.Start, bk.End)
End If
If Range("c2") = -20 Then
Set bk = wdDoc.Bookmarks("d20")
bk_name = bk.Name
Set new_range = wdDoc.Range(bk.Start, bk.End)
End If
new_range.InsertAfter (vbCrLf & excel_selection)
bk.Delete
Set bk_new = wdDoc.Bookmarks.Add(bk_name, new_range)
End Sub
|
I am getting a mismatch error on this line
Code:
Set new_range = wdDoc.Range(bk.Start, bk.End)
|