#1
|
|||
|
|||
Add braces around strikethrough text
I found a macro to add brackets around underlined text and remove the underline. Now I need to apply braces around strings of strikethrough text.
The code below works for the underlined text, but I still need to address the strikethrough text. Sub Tag_Under_Line() Selection.ClearFormatting Selection.HomeKey wdStory, wdMove Selection.Find.Font.Underline = wdUnderlineSingle Selection.Find.Execute "" Do Until Selection.Find.Found = False Selection.Font.Underline = wdUnderlineNone Selection.InsertBefore "[" Selection.InsertAfter "]" Selection.MoveRight Selection.Find.Execute "" Loop End Sub Appreciate any help! |
#2
|
||||
|
||||
Try this code
Code:
Sub Tag_Strikethroughs() Dim aRng As Range Set aRng = ActiveDocument.Range With aRng.Find .ClearFormatting .Replacement.ClearFormatting .Font.StrikeThrough = True .Text = "" Do While .Execute = True aRng.InsertBefore "{" aRng.InsertAfter "}" aRng.Characters.Last.Font.StrikeThrough = False aRng.Start = aRng.End aRng.End = ActiveDocument.Range.End Loop End With End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia Last edited by Guessed; 06-07-2023 at 07:34 PM. Reason: Pedantic edit: Changed spelling on macro name for no good reason except it bothered me |
#3
|
|||
|
|||
This worked perfectly!
So now that I have two working macros for this task, is there a way they can run together as one code or is it best to run the two macros separately? Many, many thanks! |
#4
|
||||
|
||||
You can either paste them together or create a third macro for having options to run either or both together.
Code:
Sub RunEmBoth() Tag_Strikethroughs Tag_Under_Line End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
|||
|
|||
Code:
Sub ScratchMacro() 'A basic Word Macro coded by Gregory K. Maxey Dim oRng As Range Set oRng = ActiveDocument.Range With oRng.Find .Font.StrikeThrough = True While .Execute oRng.InsertBefore "{" oRng.InsertAfter "}" oRng.Collapse wdCollapseEnd If oRng.End = ActiveDocument.Range.End Then Exit Do Wend End With Set oRng = ActiveDocument.Range With oRng.Find .Font.Underline = wdUnderlineWords Do While .Execute oRng.InsertBefore "[" oRng.Collapse wdCollapseEnd oRng.Select oRng.Underline = wdUnderlineNone oRng.InsertAfter "]" If oRng.End = ActiveDocument.Range.End Then Exit Do Loop End With Set oRng = ActiveDocument.Range With oRng.Find .Font.Underline = wdUnderlineWords Do While .Execute oRng.Underline = wdUnderlineNone oRng.Collapse wdCollapseEnd If oRng.End = ActiveDocument.Range.End Then Exit Do Loop End With lbl_Exit: Exit Sub End Sub |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Hyperlink text automatically generated too long and has braces { } | greenman1889 | Word | 2 | 11-20-2019 03:57 PM |
Superscript directly above strikethrough | bowlfreak_not | Word | 1 | 07-04-2018 03:36 PM |
Edit an existing word document - red strikethrough when deleting | siam | Word | 1 | 11-02-2017 04:30 AM |
Spaces inside Fieldcode curly braces | MANOHAR | Word VBA | 16 | 01-10-2017 11:48 AM |
Replacing curly braces in a wildcard F&R | Ulodesk | Word | 9 | 02-21-2014 07:28 AM |