Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-07-2023, 04:49 PM
docspecial docspecial is offline Add braces around strikethrough text Windows 10 Add braces around strikethrough text Office 2021
Novice
Add braces around strikethrough text
 
Join Date: Jun 2023
Posts: 2
docspecial is on a distinguished road
Default 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!
Reply With Quote
  #2  
Old 06-07-2023, 05:41 PM
Guessed's Avatar
Guessed Guessed is offline Add braces around strikethrough text Windows 10 Add braces around strikethrough text 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

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
Reply With Quote
  #3  
Old 06-07-2023, 06:59 PM
docspecial docspecial is offline Add braces around strikethrough text Windows 10 Add braces around strikethrough text Office 2021
Novice
Add braces around strikethrough text
 
Join Date: Jun 2023
Posts: 2
docspecial is on a distinguished road
Default

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!
Reply With Quote
  #4  
Old 06-07-2023, 07:33 PM
Guessed's Avatar
Guessed Guessed is offline Add braces around strikethrough text Windows 10 Add braces around strikethrough text 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

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
Reply With Quote
  #5  
Old 06-09-2023, 10:12 AM
gmaxey gmaxey is offline Add braces around strikethrough text Windows 10 Add braces around strikethrough text Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add braces around strikethrough text Hyperlink text automatically generated too long and has braces { } greenman1889 Word 2 11-20-2019 03:57 PM
Add braces around strikethrough text Superscript directly above strikethrough bowlfreak_not Word 1 07-04-2018 03:36 PM
Add braces around strikethrough text Edit an existing word document - red strikethrough when deleting siam Word 1 11-02-2017 04:30 AM
Add braces around strikethrough text 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

Other Forums: Access Forums

All times are GMT -7. The time now is 11:35 PM.


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