Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 05-24-2021, 09:01 PM
jalve jalve is offline Duplicate paragraphs except in tables Windows 10 Duplicate paragraphs except in tables Office 2013
Novice
Duplicate paragraphs except in tables
 
Join Date: Mar 2020
Posts: 12
jalve is on a distinguished road
Default

I have been rebuilding the table of contents afterwards, that's not a problem per se, but I was just wondering if it gives a clue what is going on. There is a lot of automatic numbering in those documents, and the reason why I convert to manual numbering is that Word totally messes up autonumbering of headings when it applies the styles to wrong paragraphs.





I wonder how Word associates the styles with the paragraphs, anyway? Does it have a separate array for the styles, and if the number of paragraphs in the translated text is different for some reason, they get misaligned?



Thanks for the link to translation tools, I have been meaning to look at them at some point. Right now I need to figure out how to extract the current translated text with correct styles, though.
Reply With Quote
  #17  
Old 05-24-2021, 10:49 PM
Guessed's Avatar
Guessed Guessed is online now Duplicate paragraphs except in tables Windows 10 Duplicate paragraphs except in tables Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,967
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

I think I can see where your style movement is coming from.

Your code inserts heaps of paragraph marks. Paragraph marks is where the Paragraph style is stored. Then when you do a clean up in your second macro which removes the excess paragraph marks, the paragraph mark that ends up at the end of the paragraph comes from the trailing paragraph (hence the style below gets applied to the paragraph above).

If you modify the first macro to avoid inserting extra paragraph marks then you won't need to merge paragraphs later on. Alternatively, you could remove the empty paragraphs instead of replacing two (or more) consecutive paragraph marks with one.

I would fix the first macro and get rid of the extra paragraphs right up front to simplify the later processing.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #18  
Old 05-24-2021, 11:59 PM
jalve jalve is offline Duplicate paragraphs except in tables Windows 10 Duplicate paragraphs except in tables Office 2016
Novice
Duplicate paragraphs except in tables
 
Join Date: Mar 2020
Posts: 12
jalve is on a distinguished road
Default

I think you're on the right track!


I made some progress myself in the meantime. I commented out the part in Graham's second macro which I didn't understand:


' With oRng.Find
' Do While .Execute(findText:="^13{2,}", MatchWildcards:=True)
' oRng.Text = Chr(13)
' oRng.ParagraphFormat.SpaceAfter = 12
' oRng.Collapse 0
' Loop
' End With



After running the second macro without those lines, I ended up with a document that has the styles applied to correct paragraphs, but with lots of empty paragraphs. So, I suppose those lines are intended to remove the empty paragraphs, but they also do something to mess up the styles.
Reply With Quote
  #19  
Old 05-25-2021, 01:45 AM
jalve jalve is offline Duplicate paragraphs except in tables Windows 10 Duplicate paragraphs except in tables Office 2016
Novice
Duplicate paragraphs except in tables
 
Join Date: Mar 2020
Posts: 12
jalve is on a distinguished road
Default

If I understand correctly, those lines look for occurrences of two consequtive paragraph marks, and then replace them with one paragraph mark Chr(13). Now, the question is, where does that replacement paragraph mark get its style from? Probably not from the first paragraph mark. Is there any way to read the style of the first paragraph mark and apply it to the replacement paragraph mark?
Reply With Quote
  #20  
Old 05-25-2021, 03:20 AM
Guessed's Avatar
Guessed Guessed is online now Duplicate paragraphs except in tables Windows 10 Duplicate paragraphs except in tables Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,967
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

As I said earlier, it is better to avoid the extra paragraphs in the first place.

The find/replace method is fast but a slower method of removing the empty paragraphs will also work without the side-effect.
Code:
Sub KillEmpties()
  Dim i As Long
  For i = ActiveDocument.Paragraphs.Count To 1 Step -1
    If Len(ActiveDocument.Paragraphs(i).Range.Text) = 1 Then ActiveDocument.Paragraphs(i).Range.Delete
  Next i
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #21  
Old 05-25-2021, 05:14 AM
jalve jalve is offline Duplicate paragraphs except in tables Windows 10 Duplicate paragraphs except in tables Office 2016
Novice
Duplicate paragraphs except in tables
 
Join Date: Mar 2020
Posts: 12
jalve is on a distinguished road
Default

IT WORKED! It took a while to run, but slow that works beats fast that doesn't! Thank you very much for your help, Andrew! I wish I knew how to give you the proper kudos, but this thread was marked solved already last year...
Reply With Quote
  #22  
Old 05-26-2021, 07:38 PM
macropod's Avatar
macropod macropod is offline Duplicate paragraphs except in tables Windows 10 Duplicate paragraphs except in tables Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I'd approach the task rather differently:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Tbl As Table, Rng As Range, r As Long
With ActiveDocument
  Do While .Tables.Count > 0
    .Tables(1).Delete
  Loop
  Set Tbl = .Range.ConvertToTable
  With Tbl
    .Columns.Add
    .PreferredWidthType = wdPreferredWidthPercent
    .PreferredWidth = 100
    For r = 1 To .Rows.Count
      Set Rng = .Cell(r, 1).Range
      Rng.End = Rng.End - 1
      With .Cell(r, 2).Range
        .FormattedText = Rng.FormattedText
        .LanguageID = wdEnglishAUS      'set your target language
        .Editors.Add wdEditorEveryone
      End With
    Next
  End With
  .Protect Type:=wdAllowOnlyReading
End With
Application.ScreenUpdating = True
End Sub
The above code deletes all existing tables, then converts what remains to a two-column table, with the same content in both columns, the second of which remains unprotected. This gives you a document in which you'll have the original content on the left and your translation text on the right, with rows aligned at the paragraph level.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
4605, copy/paste paragraph, tables

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicate paragraphs except in tables delete 1 or 2 adjacent duplicate paragraphs, macro moorea21 Word 4 11-01-2018 12:53 PM
Duplicate paragraphs except in tables How to find duplicate phrases/paragraphs in a long document iamgator Word VBA 5 12-27-2016 01:34 AM
Duplicate paragraphs except in tables Using VB.Net 2010 I cannot duplicate tables in the correct place AaaTeX Word Tables 3 08-03-2014 07:00 PM
Show & hide paragraphs, parts of tables, etc Preloader Word 2 10-19-2013 02:37 PM
Duplicate paragraphs except in tables add the functionality to show & hide paragraphs, parts of tables, etc pgwolfe Word 3 09-24-2013 07:58 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:20 PM.


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