Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 05-05-2023, 11:52 AM
Italophile Italophile is offline Change style of portion of paragraph Windows 11 Change style of portion of paragraph Office 2021
Expert
 
Join Date: Mar 2022
Posts: 564
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Although you may think linked styles to be cumbersome, this is precisely the use case that they were designed for.

As their name suggests, linked styles consist of two separate styles - a paragraph style and a character style with the same name plus the suffix " Char". When a linked style is applied via the UI Word decides which style to apply dependent on context.

When applied via VBA it is up to you to decide which style to apply.

To apply a heading style to the entire paragraph you can either use the name:
Code:
Selection.Range.Style = "Heading 2"
or, especially valuable if the user's OS language isn't English, the enum:
Code:
Selection.Range.Style = wdStyleHeading2
To apply the character style you can either use the name directly:
Code:
Selection.Range.Style = "Heading 2 Char"
or construct the name:
Code:
Selection.Range.Style = ActiveDocument.Styles(wdStyleHeading2).NameLocal & " Char"
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Change style of portion of paragraph Word 2007: Unable to change character style, when using a linked Char/Para style format Last Chance Word 3 06-09-2021 12:52 PM
Why does paragraph inherit style of the following paragraph? WADEVCAMP Word VBA 2 04-08-2019 02:13 PM
Change style of portion of paragraph How to globally change the formatting of a bullet style to another style? ravl13 Word 5 03-10-2013 05:04 PM
Don't indent the fist line of the first paragraph after a style change Inspirement Word 1 04-08-2012 05:30 AM
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 03:38 PM.


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