Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-23-2024, 02:37 PM
Jakov93 Jakov93 is offline Format Paragraphs Only if It Contains Mixed Text Formatting VBA Windows 10 Format Paragraphs Only if It Contains Mixed Text Formatting VBA Office 2010
Advanced Beginner
Format Paragraphs Only if It Contains Mixed Text Formatting VBA
 
Join Date: Jul 2021
Posts: 45
Jakov93 is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 03-23-2024, 07:38 PM
Charles Kenyon Charles Kenyon is offline Format Paragraphs Only if It Contains Mixed Text Formatting VBA Windows 11 Format Paragraphs Only if It Contains Mixed Text Formatting VBA Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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.
Reply With Quote
  #3  
Old 03-24-2024, 01:04 PM
Jakov93 Jakov93 is offline Format Paragraphs Only if It Contains Mixed Text Formatting VBA Windows 10 Format Paragraphs Only if It Contains Mixed Text Formatting VBA Office 2010
Advanced Beginner
Format Paragraphs Only if It Contains Mixed Text Formatting VBA
 
Join Date: Jul 2021
Posts: 45
Jakov93 is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 03-24-2024, 04:05 PM
Guessed's Avatar
Guessed Guessed is offline Format Paragraphs Only if It Contains Mixed Text Formatting VBA Windows 10 Format Paragraphs Only if It Contains Mixed Text Formatting VBA Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #5  
Old 03-24-2024, 08:43 PM
Jakov93 Jakov93 is offline Format Paragraphs Only if It Contains Mixed Text Formatting VBA Windows 10 Format Paragraphs Only if It Contains Mixed Text Formatting VBA Office 2010
Advanced Beginner
Format Paragraphs Only if It Contains Mixed Text Formatting VBA
 
Join Date: Jul 2021
Posts: 45
Jakov93 is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
Have you tried the autoformatting function to apply styles in a single step? Then reset the font settings.
No Andrew No
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
Reply With Quote
  #6  
Old 03-24-2024, 09:46 PM
Guessed's Avatar
Guessed Guessed is offline Format Paragraphs Only if It Contains Mixed Text Formatting VBA Windows 10 Format Paragraphs Only if It Contains Mixed Text Formatting VBA Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
This assumes the underlying paragraph style on the 'mixed' paragraphs is non-bold and non-italic.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #7  
Old 03-25-2024, 04:36 AM
Jakov93 Jakov93 is offline Format Paragraphs Only if It Contains Mixed Text Formatting VBA Windows 10 Format Paragraphs Only if It Contains Mixed Text Formatting VBA Office 2010
Advanced Beginner
Format Paragraphs Only if It Contains Mixed Text Formatting VBA
 
Join Date: Jul 2021
Posts: 45
Jakov93 is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
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
Thanks Andrew so much
It works perfectly
You will save me time on work with future lectures
I can't thank you enough
Billion Thanks
Reply With Quote
  #8  
Old 03-25-2024, 01:58 PM
TessaMurillo TessaMurillo is offline Format Paragraphs Only if It Contains Mixed Text Formatting VBA Windows Vista Format Paragraphs Only if It Contains Mixed Text Formatting VBA Office 2010
Advanced Beginner
 
Join Date: Mar 2024
Posts: 33
TessaMurillo has a little shameless behaviour in the past
Default

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.
Reply With Quote
Reply



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
Format Paragraphs Only if It Contains Mixed Text Formatting VBA How to duplicate paragraphs & format them effimera Word VBA 2 12-20-2021 04:40 AM
Format Paragraphs Only if It Contains Mixed Text Formatting VBA trouble replacing mixed hidden and nonhidden text w0lfshad3 Word 1 05-01-2016 02:23 PM
Format Paragraphs Only if It Contains Mixed Text Formatting VBA Find and replace with mixed formatting pogonoforysci1 Word 2 09-26-2012 09:16 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:56 AM.


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