View Single Post
 
Old 07-11-2023, 03:48 AM
Mai_ibs Mai_ibs is offline Windows 10 Office 2019
Novice
 
Join Date: Jul 2023
Posts: 2
Mai_ibs is on a distinguished road
Default Macro stops working after the first paragraph

Hello,

I need to create a macro to duplicate each of the paragraphs in a file (including the content within tables), maintaining the same formatting, and then hide the first paragraph in each instance (including the content within tables).

I checked this forum and I found a macro: it duplicates, keeps formatting and hide the content; however it stops working after the first paragraph. I don't know why.

This is the macro:

Sub Macro1()
Dim oRng As Range
Dim oPara As Range, oNewPara As Range
Dim i As Long
Set oRng = Selection.Range
If oRng.End = ActiveDocument.Range.End Then
oRng.InsertParagraphAfter
End If
For i = oRng.Paragraphs.Count To 1 Step -1
Set oPara = oRng.Paragraphs(i).Range
Set oNewPara = oPara.Duplicate
oNewPara.Collapse 0
oNewPara.FormattedText = oPara.FormattedText
Next i
lbl_Exit:
Set oRng = Nothing
Set oPara = Nothing
Set oNewPara = Nothing
Exit Sub
End Sub


Thanks!
Reply With Quote