Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-11-2024, 07:12 AM
Shelley Lou Shelley Lou is offline VBA Plain Definitions formatted Bold Windows 10 VBA Plain Definitions formatted Bold Office 2016
Expert
VBA Plain Definitions formatted Bold
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA Plain Definitions formatted Bold

I have some code that is supposed to format plain text definitions with quotes, e.g. the "Property" to the "Property" upon selection. I've set the range to Selection.Range but when selecting the text and running the code, it is formatting all plain text within quotes that have not been selected.

The code needs to be able to handle one selection or multiple selections. I'm not sure where I'm going wrong.



Code:
Sub PlainDefinition_FormatBold()
'Select one or more definitions with plain text and plain quotes and format bold
Dim rng As Range
Application.ScreenUpdating = False
If Selection.Type = wdSelectionIP Then
 'MsgBox Prompt:="You have not selected any text!"
 MsgBox "You have not selected any text!", vbExclamation, "Invalid selection"
 Exit Sub
End If
Set rng = Selection.Range
With rng.Find
   .ClearFormatting
   .Replacement.ClearFormatting
   .Forward = False
   .Wrap = wdFindStop
   .Format = True
   .MatchWildcards = True
   .text = "[""""]*[""""]" 'Find plain text within plain quotes
   .Replacement.text = "^&" 'Format bold
   .Replacement.Font.Bold = True 'Replacement text is bold
   .Execute Replace:=wdReplaceAll
   .text = "[\(\)]" 'Find plain text with plain quotes within brackets
   .Replacement.text = "^&" 'Format bold
   .Replacement.Font.Bold = False
   .Execute Replace:=wdReplaceAll
   Application.ScreenUpdating = True
   End With
   End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Plain Definitions formatted Bold VBA format plain quotes to bold quotes Shelley Lou Word VBA 3 02-11-2024 05:56 AM
Bold Header if it is not Bold (Check to see if it is Bold) armendarizj Word 2 01-06-2022 05:45 PM
VBA Plain Definitions formatted Bold Help with Definitions Macro Shelley Lou Word VBA 3 12-11-2020 01:39 AM
VBA Plain Definitions formatted Bold Replacing formatted bullet points as a plain text character? onlywonderboy Word VBA 6 02-21-2017 03:20 PM
VBA Plain Definitions formatted Bold How to update fields in all header definitions ChrisBrewster Word VBA 2 02-10-2014 10:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:40 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