Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-20-2021, 09:07 AM
gmaxey gmaxey is offline setting paragraph style removes inlines incidentally. Why? Windows 10 setting paragraph style removes inlines incidentally. Why? Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,600
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default


Paul, here both of those returned the same result the OP is seeing.


Ruud, back to your original observation, it does seem that the length of the italic string in the paragraph text is having and affect. I copied your line 2 as lines 4 and 5. Then shortened the italic string in line 4. Ran your macro and lines 2 and 5 were not converted to all normal font.

I don't know why that is happening. I don't know how helpful this will be for your production documents, but for this example, this worked:

Code:
Public Sub flatten()
Dim oRng As Range
Dim wPara As Word.Paragraph
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Font.Italic = True
    .Replacement.Text = "<i>^&</i>"
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
  For Each wPara In Word.ActiveDocument.Paragraphs
    wPara.Style = ActiveDocument.styles(wdStyleNormal).NameLocal
  Next
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .ClearFormatting
    .Text = "(\<i\>)(*)(\</i\>)"
    .MatchWildcards = True
    .Replacement.Text = "\2"
    .Replacement.Font.Italic = True
    .Execute Replace:=wdReplaceAll
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #2  
Old 01-20-2021, 01:07 PM
macropod's Avatar
macropod macropod is offline setting paragraph style removes inlines incidentally. Why? Windows 10 setting paragraph style removes inlines incidentally. Why? Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,371
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

Quote:
Originally Posted by gmaxey View Post
Paul, here both of those returned the same result the OP is seeing.
In my testing, both restored the Normal formatting for the entire document.

If I misread the OP's requirement and the italics are to be retained, that's as simple as:
Code:
Public Sub Flatten()
ActiveDocument.Range.Style = wdStyleNormal
End Sub
or:
Code:
Public Sub Flatten()
ActiveDocument.Range.ParagraphFormat.Reset
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA - (Re-) Setting a Table Style mikejvir PowerPoint 2 12-04-2019 10:15 AM
Why does paragraph inherit style of the following paragraph? WADEVCAMP Word VBA 2 04-08-2019 02:13 PM
Setting part of a paragraph bold Fred256 Word VBA 4 10-07-2016 02:54 PM
setting paragraph style removes inlines incidentally. Why? Style seems to inherit bold setting from previous style Jennifer Murphy Word 3 02-16-2012 04:18 PM
Character style stripped while applying paragraph style sams_gates Word 0 08-29-2009 02:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:36 AM.


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