Hi Everyone,
I'm having issues merging some cells in a table that I created with VBA in a word document. It gives me the error "Run-time error '5941': The requested member of hte collection does not exist" even though I just wrote to the cells in the lines above.
Any suggestions??
Selection.GoTo What:=wdGoToBookmark, Name:="\EndOfDoc"
ActiveDocument.Range.Tables.Add Range:=Selection.Range, NumRows:=cntTotal, NumColumns:= _
4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitContent
With Selection.Tables(1)
.Range.Font.Name = "Arial"
.Range.Font.size = 10
.Rows.Height = 1
.Rows.Alignment = wdAlignRowCenter
.Columns(1).Width = 220
.Columns(2).Width = 220
.Columns(3).Width = 220
.Columns(4).Width = 75
.Cell(1, 1).Range.Bold = True
.Cell(1, 2).Range.Bold = True
.Cell(1, 3).Range.Bold = True
.Cell(1, 4).Range.Bold = True
.Cell(1, 1).Range.Text = "Requirement"
.Cell(1, 2).Range.Text = "Test Objective"
.Cell(1, 3).Range.Text = "Test Strategy/Approach"
.Cell(1, 4).Range.Text = "Documentation" & vbCrLf & "PR-" & txtDHFNum.Value & "-" & txtProtNum.Value
cnt = 2
For i = 1 To UBound(listReq)
.Cell(cnt, 1).Range.Text = listReq(i).reqNum & vbCrLf & listReq(i).reqDesc
For j = 1 To UBound(listReq(i).objList)
.Cell(cnt + j - 1, 2).Range.Text = listReq(i).reqNum & "." & j & " Verify that " & listReq(i).objList(j).objDesc
.Cell(cnt + j - 1, 3).Range.Text = listReq(i).objList(j).stratDesc
.Cell(cnt + j - 1, 4).Range.Text = listReq(i).objList(j).section
.Cell(1, 1).Merge MergeTo:=.Cell(2, 1)
Next
' HERE is the problem command
.Cell(1, 1).Merge MergeTo:=.Cell(2, 1)
' ****************************
cnt = cnt + UBound(listReq(i).objList)
Next
End With
Thanks!
I'm having issues merging some cells in a table that I created with VBA in a word document. It gives me the error "Run-time error '5941': The requested member of hte collection does not exist" even though I just wrote to the cells in the lines above.
Any suggestions??
Selection.GoTo What:=wdGoToBookmark, Name:="\EndOfDoc"
ActiveDocument.Range.Tables.Add Range:=Selection.Range, NumRows:=cntTotal, NumColumns:= _
4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitContent
With Selection.Tables(1)
.Range.Font.Name = "Arial"
.Range.Font.size = 10
.Rows.Height = 1
.Rows.Alignment = wdAlignRowCenter
.Columns(1).Width = 220
.Columns(2).Width = 220
.Columns(3).Width = 220
.Columns(4).Width = 75
.Cell(1, 1).Range.Bold = True
.Cell(1, 2).Range.Bold = True
.Cell(1, 3).Range.Bold = True
.Cell(1, 4).Range.Bold = True
.Cell(1, 1).Range.Text = "Requirement"
.Cell(1, 2).Range.Text = "Test Objective"
.Cell(1, 3).Range.Text = "Test Strategy/Approach"
.Cell(1, 4).Range.Text = "Documentation" & vbCrLf & "PR-" & txtDHFNum.Value & "-" & txtProtNum.Value
cnt = 2
For i = 1 To UBound(listReq)
.Cell(cnt, 1).Range.Text = listReq(i).reqNum & vbCrLf & listReq(i).reqDesc
For j = 1 To UBound(listReq(i).objList)
.Cell(cnt + j - 1, 2).Range.Text = listReq(i).reqNum & "." & j & " Verify that " & listReq(i).objList(j).objDesc
.Cell(cnt + j - 1, 3).Range.Text = listReq(i).objList(j).stratDesc
.Cell(cnt + j - 1, 4).Range.Text = listReq(i).objList(j).section
.Cell(1, 1).Merge MergeTo:=.Cell(2, 1)
Next
' HERE is the problem command
.Cell(1, 1).Merge MergeTo:=.Cell(2, 1)
' ****************************
cnt = cnt + UBound(listReq(i).objList)
Next
End With
Thanks!