I have already checked what I am asking now but I couldn't still solve my problem which is the following:
I try to delete text between two bookmarks in a Word document - that part I have solved. However, I have many bookmark pairs and I would like to delete text in between each pair. So, I decided to enter the bookmarks in two arrays: arr_B for beginning of the text part and arr_E for the end of the text part and between them text should be deleted. I have tried like this:
Sub Macro2()
Dim arr_B As Variant
Dim arr_E As Variant
Dim i As Long
Dim k As Long
Dim element As Variant
arr_B = Array("B1_RSD1", "B2_RSD2")
arr_E = Array("E1_RSD1", "E2_RSD2")
For Each element In arr_B
For Each element In arr_E
Set rngStart = ActiveDocument.Bookmarks(i).Range
Set rngEnd = ActiveDocument.Bookmarks("k").Range
ActiveDocument.Range(rngStart.Start, rngEnd.End).Select
Selection.Delete
Exit For
Next k
Next i
End Sub
However, above code gives the error
For control variable already in use
I couldn't find out how to solve this problem. I would appreciate any help and many thanks in advance.
element
for more than oneFor
loop. Declare, for example:Dim element_B as Variant, element_E as Variant
and then use those in their respectiveFor
loops. – Cindy Meister