HI,
Am getting a " run time error 5941:", (The requested member of the collection does not exists.)
This is actual requirement.
Tagged AAA at the beginning of the active table, then if we select "Yes" It should moved to next table, again if we select "Yes" it should moved to next table, if we select "No" then it should stop moving to next table and tagged BBB at the end of that table.
Could you plese review the code once and do the needful.
Code:
Sub Text_Insert()
Dim i As Long, j As Long
Dim rng As Range
If Selection.Information(wdWithInTable) = False Then
MsgBox "The selection is not inside a table."
Exit Sub
End If
With ActiveDocument
For i = 1 To .Tables.Count
If Selection.Range.Start > .Tables(i).Range.Start And Selection.Range.End < .Tables(i).Range.End Then
Exit For
End If
Next i
Set rng = .Tables(i).Range
rng.Collapse wdCollapseStart
rng.MoveStart wdCharacter, -1
rng.InsertBefore vbCr & "AAA"
For j = i + 1 To .Tables.Count
If MsgBox("Do you wish to insert the End tag after this table", vbQuestion + vbYesNo) = vbYes Then
Set rng = .Tables(j).Range
rng.Collapse wdCollapseEnd
rng.InsertAfter "BBB" & vbCr
Exit For
End If
Next j
End With
End Sub
Your Help is Highly Appreciated and Thanks in Advance..