5941 The requested member of the collection does not exist...Please help!

Jun 23, 2016
Reaction score
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
End If
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).

Wrd.ActiveDocument.SaveAs (Application.ActiveWorkbook.Path + "\" + FolderName + "\" + FName + ".docx")

myRow = myRow + 1
FName = Worksheets("Data").Cells(myRow, 1).Value

Worksheets("Code Info").Activate 'focus on the "Code Info" worksheet
End Sub

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question