I have some issues programming a mail merge because every content created by my code has to be deleted in order to be not in the way for the next letter in the merging process.
So I wrote a test Macro just to create some tables and delete them.
Here is my progress - It can be run in an new empty Word-File with a Bookmark called "test"
Sub TabsNText()
Const k As Integer = 2
Dim doc As Document
Dim rng As Range
Dim tab_rngs(k) As Range
Dim txt_rngs(k) As Range
Dim tbl As Table
Set doc = Word.ActiveDocument
Set rng = doc.Bookmarks("test").Range
Dim i As Integer
For i = 1 To k
Set txt_rngs(i) = rng
rng.Text = "Title " & i
rng.Collapse Direction:=wdCollapseEnd
rng.InsertParagraphAfter
rng.Collapse Direction:=wdCollapseEnd
Set tab_rngs(i) = rng
Set tbl = doc.Tables.Add(rng, 3, 3)
tbl.Cell(1, 1).Range.Text = "Table" & i
tbl.Borders.Enable = True
Set rng = tbl.Range
rng.Collapse Direction:=wdCollapseEnd
rng.InsertParagraphAfter
rng.Collapse Direction:=wdCollapseEnd
Next i
rng.Select
MsgBox ("Now, let's delete that!")
For i = 1 To k
txt_rngs(i).Text=""
tab_rngs(i).Tables(1).Delete
doc.Bookmarks.Add Name:="test", Range:=rng
Next i
End Sub
You see. Tables will be deleted properly. But what is about the text and the paragraphs? Is there a method to just make a selection from a start point to some end point and delete all of its content.