I am working on Macro that copies data from NamedCells in Excel and places them at specific Bookmarks in a Word template. I am getting a run time error 9 when the code gets to the pasting data at Bookmarks line. Further, some of the data is getting pasted into the template but "Title1" is getting pasted at BookmarkTitle2 location and Title2 is getting pasted at BookmarkTitle3... then the run time error comes up...
Code is below....
Can someone tell me what I am doing wrong?
Sub CopyExcelTitlesToWord()
Dim WordApp As Word.Application
Dim myDoc As Word.Document
Dim WordTable As Word.Table
Dim BookmarkArray As Variant
Dim Title(1 To 3) As Range
Dim x As Integer
'List the tables/charts from excel you want to Word
Set Title(1) = ThisWorkbook.Worksheets("TopPage").Range("Title1")
Set Title(2) = ThisWorkbook.Worksheets("TopPage").Range("Title2")
Set Title(3) = ThisWorkbook.Worksheets("TopPage").Range("Title3")
'List of corresponding Word Bookmarks to paste the tables/charts to in Word
BookmarkArray = Array("BookmarkTitle1", "BookmarkTitle2", "BookmarkTitle3")
'Optimize Code
Application.ScreenUpdating = False
Application.EnableEvents = False
'Open Word template
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = True
'Open existing template in Word
Set myDoc = WordApp.Documents.Open("C:\Users\xxx\Desktop\TemplateTest1.docx")
'Loop Through and Copy/Paste Multiple Excel NamedCells
For x = LBound(Title) To UBound(Title)
Title(x).Select
Selection.Copy
'Paste Title into MS Word (using inserted Bookmarks -> ctrl+shift+F5). 'Name the Bookmarks so they are in Series so they are easy to loop through.
myDoc.Bookmarks(BookmarkArray(x)).Range.PasteExcelTable False, False, True
Next x
'Optimize Code
Application.ScreenUpdating = True
Application.EnableEvents = True
'Clear The Clipboard
Application.CutCopyMode = False
End Sub