Hello. I am very new to programming and I am attempting to auto-fill reports in a Word doc from an excel database. The code below is what I have used successfully on similar doc-excel actions, but now I am getting "5941 The requested member of the collection does not exist" error on the below highlighted code. Please help!
Dim myRow As Integer
Dim Wrd As New Word.Application
Set Wrd = CreateObject("Word.Application")
Dim MergeDoc As String
Dim FName As String
Dim rName As String
Dim lName As String
Dim wdRng As Word.Range
Dim FolderName As String
Dim bmkRow As Integer
Dim bmkName As String
Dim bmkCol As Integer
MergeDoc = Application.ActiveWorkbook.Path
MergeDoc = MergeDoc + "\" + Worksheets("Code Info").Cells(2, 2).Value
FolderName = Worksheets("Code Info").Cells(3, 2).Value
myRow = Worksheets("Code Info").Cells(4, 2).Value
FName = Worksheets("Data").Cells(myRow, 1).Value
Do While FName <> " "
Wrd.Documents.Add MergeDoc
Wrd.Visible = True
bmkRow = 2
bmkName = Worksheets("Setup").Cells(bmkRow, 1).Value
Do While bmkName <> ""
bmkCol = Worksheets("Setup").Cells(bmkRow, 2).Value
If InStr(bmkName, "chart_") = 1 Then
bvalue = Worksheets("Data").Cells(myRow, bmkCol).Value
If Not IsEmpty(bvalue) Then
Set wdRng = Wrd.ActiveDocument.Bookmarks.Item(bmkName).Range
Worksheets("Charts").ChartObjects(bvalue).Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy
wdRng.Paste
End If
Else
With Wrd.ActiveDocument.Bookmarks
.Item(bmkName).Range.Text = Worksheets("Data").Cells(myRow, bmkCol).Value
End With
End If
bmkRow = bmkRow + 1
bmkName = Worksheets("Setup").Cells(bmkRow, 1).
Loop
Wrd.ActiveDocument.SaveAs (Application.ActiveWorkbook.Path + "\" + FolderName + "\" + FName + ".docx")
Wrd.ActiveDocument.Close
myRow = myRow + 1
FName = Worksheets("Data").Cells(myRow, 1).Value
Loop
Worksheets("Code Info").Activate 'focus on the "Code Info" worksheet
End Sub
Dim myRow As Integer
Dim Wrd As New Word.Application
Set Wrd = CreateObject("Word.Application")
Dim MergeDoc As String
Dim FName As String
Dim rName As String
Dim lName As String
Dim wdRng As Word.Range
Dim FolderName As String
Dim bmkRow As Integer
Dim bmkName As String
Dim bmkCol As Integer
MergeDoc = Application.ActiveWorkbook.Path
MergeDoc = MergeDoc + "\" + Worksheets("Code Info").Cells(2, 2).Value
FolderName = Worksheets("Code Info").Cells(3, 2).Value
myRow = Worksheets("Code Info").Cells(4, 2).Value
FName = Worksheets("Data").Cells(myRow, 1).Value
Do While FName <> " "
Wrd.Documents.Add MergeDoc
Wrd.Visible = True
bmkRow = 2
bmkName = Worksheets("Setup").Cells(bmkRow, 1).Value
Do While bmkName <> ""
bmkCol = Worksheets("Setup").Cells(bmkRow, 2).Value
If InStr(bmkName, "chart_") = 1 Then
bvalue = Worksheets("Data").Cells(myRow, bmkCol).Value
If Not IsEmpty(bvalue) Then
Set wdRng = Wrd.ActiveDocument.Bookmarks.Item(bmkName).Range
Worksheets("Charts").ChartObjects(bvalue).Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy
wdRng.Paste
End If
Else
With Wrd.ActiveDocument.Bookmarks
.Item(bmkName).Range.Text = Worksheets("Data").Cells(myRow, bmkCol).Value
End With
End If
bmkRow = bmkRow + 1
bmkName = Worksheets("Setup").Cells(bmkRow, 1).
Loop
Wrd.ActiveDocument.SaveAs (Application.ActiveWorkbook.Path + "\" + FolderName + "\" + FName + ".docx")
Wrd.ActiveDocument.Close
myRow = myRow + 1
FName = Worksheets("Data").Cells(myRow, 1).Value
Loop
Worksheets("Code Info").Activate 'focus on the "Code Info" worksheet
End Sub