VBA Run-time error: '91'
Hi! I am getting a run-time error: '91' regarding Object variable or With block variable not set. Does anyone know what is causing the issue? Using this macro to extract excel cell values and populate in the bookmarked areas of a distinct word document.
the filepaths are real filepaths on my desktop. Thanks!!
Sub PopulateTemplate()
Dim Loadarray
Loadarray = ActiveSheet.UsedRange.Value
Dim objWrd As New Word.Application
'objWrd.Visible = True
Dim lngRow As Long
For lngRow = 2 To UBound(Loadarray, 1)
Dim ojtTpl As Document
Set objTpl = objWrd.Documents.Open("filpath" & "word.doc", , True, False)
Dim objBM As Bookmark
For Each objBM In objTpl.Bookmarks
Dim lngCol As Long
For lngCol = 1 To UBound(Loadarray, 2)
If objBM.Range.Text = "[[" & Loadarray(1, lngCol) & "]]" Then
'objBM.Select
'objWrd.Selection.TypeText Cells(lngRow, lngCol)
objBM.Range.Text = Loadarray(lngRow, lngCol)
Exit For
End If
Next
Next
objTpl.SaveAs "filepath" & Loadarray(lngRow, 1) & ".doc"
objTpl.Close False
Set objTpl = Nothing
Next
objWrd.Quit False
End Sub
Posted Apr 26, 2017, 6:07 PM UTC · edited
54