View Single Post
 
Old 01-15-2021, 03:25 AM
rgros rgros is offline Windows 10 Office 2019
Novice
 
Join Date: Jan 2021
Posts: 8
rgros is on a distinguished road
Default setting paragraph style removes inlines incidentally. Why?

Hi, I am new to this forum. I hope I manage to ask this question properly in one go.

The problem I am facing: I have a whole lot of word macro's running on documents to prepare it for conversion to XML.
Last week, I got a report of italic inlines disappearing in the macro output.
I traced this back to a routine that removes the paragraph styles from the document. In some cases the setting of the paragraph style has a side effect that italic inlines are removed.
I certainly want to preserve them in order to get the expected output.

I made a minimal example to show this behaviour.
I hope you can explain me why word behaves like this and that you can advise me what I can do in the macro are to prevent this from happening.

I have a document that looks like this:

abcdef 123456
abcdef 1234567
abcdef 12345
abcdef 1234

I run this macro on it to remove any user defined paragraph styles:
Code:
Public Sub flatten() 
    Dim wPara As Word.Paragraph 
      For Each wPara In Word.ActiveDocument.Paragraphs
         wPara.range.Select
         wPara.style = ActiveDocument.styles(wdStyleNormal).NameLocal
     Next
 End Sub
The result is:

abcdef 123456
abcdef 1234567
abcdef 12345
abcdef 1234

in the first two lines, the italic inline is deleted, whereas the last two lines still have it.
I found out the inline is deleted when the number of inline characters exceeds the number of normal characters (this is the case in the first two paragraphs).

As said, I want to preserve the inlines in all situations. I hope this is not a FAQ that I missed.

Thanks in advance, Ruud
Reply With Quote