#16
|
|||
|
|||
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. |
#17
|
||||
|
||||
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 |
#18
|
|||
|
|||
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. |
#19
|
|||
|
|||
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?
|
#20
|
||||
|
||||
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 |
#21
|
|||
|
|||
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...
|
#22
|
||||
|
||||
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
4605, copy/paste paragraph, tables |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
delete 1 or 2 adjacent duplicate paragraphs, macro | moorea21 | Word | 4 | 11-01-2018 12:53 PM |
How to find duplicate phrases/paragraphs in a long document | iamgator | Word VBA | 5 | 12-27-2016 01:34 AM |
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 |
add the functionality to show & hide paragraphs, parts of tables, etc | pgwolfe | Word | 3 | 09-24-2013 07:58 PM |