Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-28-2023, 02:08 PM
tanko tanko is offline Change style of portion of paragraph Windows 10 Change style of portion of paragraph Office 2016
Novice
Change style of portion of paragraph
 
Join Date: Jan 2021
Posts: 17
tanko is on a distinguished road
Default Change style of portion of paragraph

Hi, I've got a simple macro that I want to use to find all paragraphs of a particular style, and then change a portion of that paragraph to a new style. The purpose is to tag the first portion as Heading 2 so it will show up in the TOC without the rest of the body of that paragraph. When I manually set the paragraph's style to my custom "Level 2" style, I can manually select the caption of that paragraph and change it to "Heading 2." Only the selected portion, the caption, will be changed. However, when I run this macro, it changes the style for the entire paragraph. How can I make Word apply the style only to the first sentence, which is the caption? I've tried using para.range.Sentence(1).select, and that doesn't work either.

For example, the following paragraph with Level 2 style:


Quote:
1.1 Proxies. At all meetings of Members, a Member may vote in person or by proxy executed in writing by the Member. Such proxy shall be filed with the Manager before or at the time of the meeting. No proxy shall be valid after eleven (11) months from the date of its execution, unless otherwise provided in the proxy.
Becomes the following, all of which is Heading 2:
Quote:
1.1 Proxies. At all meetings of Members, a Member may vote in person or by proxy executed in writing by the Member. Such proxy shall be filed with the Manager before or at the time of the meeting. No proxy shall be valid after eleven (11) months from the date of its execution, unless otherwise provided in the proxy.
Code:
Sub ChangeCaptionStyle()
    Dim para        As Word.Paragraph

    For Each para In ActiveDocument.Paragraphs
        paracheck = para.Range.Sentences(1)
        If para.Style = "Level 2" Then
            para.Range.Sentences(1).Select
            Selection.Range.Style = "Heading 2"
        End If
    Next para

    Set para = Nothing
End Sub
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 07:08 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