Code to cut a paragraph that's followed by a table


Joined
Jan 2, 2020
Messages
7
Reaction score
0
Hey folks,

My people like their table captions included in the first row of a table so the caption repeats on following pages. I've written a pretty basic macro to cut a table caption, go to the table and insert a row, merge the cells, and paste the caption into that row. It works great except for one thing: because the caption is usually immediately followed by a table, cutting the caption leaves the blank paragraph marker behind (I'm sure there's a good technical reason Word does this but it's annoying).

Here's my code:

Sub PutCaptionIntoTable()
'
'
Selection.Paragraphs(1).Range.Select
Selection.Cut
Selection.GoToNext wdGoToTable
Selection.InsertRowsAbove 1
Selection.Cells.Merge
Selection.Paste
With Selection.Cells
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
Selection.Style = Word.WdBuiltinStyle.wdStyleCaption
End Sub

What's the most efficient way to delete that extra paragraph?

Thanks in advance,

Beej
 
Ad

Advertisements

Ad

Advertisements

Joined
Jan 2, 2020
Messages
7
Reaction score
0
Thanks macropod.

I'm a recent migrant from the old windowssecrets Word forum. I'm VERY happy to see you're here. You were a huge help to me many times there.
 

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

Top