#1
|
|||
|
|||
Format Paragraphs Only if It Contains Mixed Text Formatting VBA
Hi, I have such a condition 158.png I want only titles to be bold, other text must appear regular (normal), so I want to change the format of paragraphs that contain mixed format (bold, regular, italic) and change it to normal (regular) text, but keep the format if the entire paragraph is bold (titles). Thanks |
#2
|
|||
|
|||
Use Styles!
Your headings should use a heading style, perhaps one of the built-in ones modified to look the way you want. Why Use Word's Built-In Heading Styles? by Shauna Kelly Your body text should use the Body Text style, or the Normal style or one that you want. You apply the style to the paragraph and then select it and press Ctrl+Spacebar to clear any direct formatting. |
#3
|
|||
|
|||
Thank for reply
I always use styles to format my document but this sample is of my teacher, apply styles will require reformating the document from scratch, so macro will be helpful in this case. Thanks |
#4
|
||||
|
||||
Have you tried the autoformatting function to apply styles in a single step? Then reset the font settings.
Code:
ActiveDocument.Range.AutoFormat ActiveDocument.Range.Font.Reset
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
Quote:
It produces undesired results, it applies numbering to titles, images in the random distribution ...etc, it restores the document to its original version that I received from my teacher, because I use macro to change font type, color, and size for the entire document, another macro to justify each paragraph So all text will lose its formatting (by macros) after applying the reset function. my document requires the last touch, which is to change the format of paragraphs that contain mixed format (bold, regular, italic) and change it to normal (regular) text. I use macros instead of styles for my teacher documents because I just want to print them, but in a formatted way, also I don't come back to the documents after printing it, so styles have little value in this case. Thanks |
#6
|
||||
|
||||
In that case you need to examine every paragraph with a loop
Code:
Sub WipeLocalFormats() Dim aPara As Paragraph For Each aPara In ActiveDocument.Paragraphs With aPara.Range.Font If .Bold = wdUndefined Or .Italic = wdUndefined Then .Reset End With Next aPara End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#7
|
|||
|
|||
Quote:
It works perfectly You will save me time on work with future lectures I can't thank you enough Billion Thanks |
#8
|
|||
|
|||
Open your document in Microsoft Word.
Select the text you want to change. Right-click on the selected text and select Paragraph Options. In the "Font" tab, select bold. Click "OK" to apply the changes. This will change the format only for text that is in bold. The rest of the text will remain normal. If you have other requirements or questions, please let me know. Last edited by TessaMurillo; 03-26-2024 at 05:55 AM. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Format paragraphs between Start and End | RobiNew | Word VBA | 2 | 11-13-2023 10:51 AM |
how to use word vba to read header, mixed with text and shape, on last page of very section? | oyster | Word VBA | 0 | 06-28-2022 08:58 PM |
How to duplicate paragraphs & format them | effimera | Word VBA | 2 | 12-20-2021 04:40 AM |
trouble replacing mixed hidden and nonhidden text | w0lfshad3 | Word | 1 | 05-01-2016 02:23 PM |
Find and replace with mixed formatting | pogonoforysci1 | Word | 2 | 09-26-2012 09:16 AM |