Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-11-2023, 03:48 AM
Mai_ibs Mai_ibs is offline Macro stops working after the first paragraph Windows 10 Macro stops working after the first paragraph Office 2019
Novice
Macro stops working after the first paragraph
 
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
  #2  
Old 07-11-2023, 05:25 PM
Guessed's Avatar
Guessed Guessed is offline Macro stops working after the first paragraph Windows 10 Macro stops working after the first paragraph Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Is this for a language translation project?

I'm thinking you will need a method of showing/hiding either paragraph instance so there needs to be some way of identifying each series
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 07-11-2023, 05:25 PM
gmaxey gmaxey is offline Macro stops working after the first paragraph Windows 10 Macro stops working after the first paragraph Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

There was nothing in your original code that hid content:

Code:
Sub Macro1()
Dim oRng As Range
Dim oPara As Range, oNewPara As Range
Dim i As Long
Set oRng = ActiveDocument.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
  oPara.Font.Hidden = True
Next i
lbl_Exit:
Set oRng = Nothing
Set oPara = Nothing
Set oNewPara = Nothing
Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #4  
Old 07-12-2023, 01:40 AM
Mai_ibs Mai_ibs is offline Macro stops working after the first paragraph Windows 10 Macro stops working after the first paragraph Office 2019
Novice
Macro stops working after the first paragraph
 
Join Date: Jul 2023
Posts: 2
Mai_ibs is on a distinguished road
Default

Thanks Greg and Andrew!

Yes, this is for a translation project.

Thanks for adding that line, Greg. I added it on my local but after several tests, I forgot to paste it here. Anyways, I'm still having issues

Thanks again for checking!
Reply With Quote
Reply

Tags
duplicate sentences, hide, paragraph formatting



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro stops working after the first paragraph Drag and Drop Stops Working TucsonJack Word 7 04-26-2023 04:36 PM
Macro stops working after the first paragraph when using find in vba several times it stops working Salah Word VBA 1 03-02-2017 03:02 AM
OneNote Clipper Addon stops working dannyetlv OneNote 0 08-05-2016 09:12 AM
Autotransition stops while working on extended desktop IT1 PowerPoint 1 11-04-2015 11:19 PM
Outlook Stops Working TOKonline Outlook 0 09-26-2014 05:39 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:53 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft