Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-16-2021, 07:03 PM
ar100j ar100j is offline Automatically Inserting Brackets to EACH selected line Windows 10 Automatically Inserting Brackets to EACH selected line Office 2019
Novice
Automatically Inserting Brackets to EACH selected line
 
Join Date: May 2021
Posts: 3
ar100j is on a distinguished road
Lightbulb Automatically Inserting Brackets to EACH selected line

Hello guys,

I need to ask if it's possible to do amend on the below code related to Inserting Brackets I need to add the brackets in each bold sentences after selecting the same format




Quote:
Sub AddBrackets()
Dim iCount As Integer
iCount = 1
While Right(Selection.Text, 1) = " " Or _
Right(Selection.Text, 1) = Chr(13)
Selection.MoveLeft Unit:=wdCharacter, Count:=1, _
Extend:=wdExtend
iCount = iCount + 1
Wend

Selection.InsertAfter "]"
Selection.InsertBefore "["
Selection.MoveRight Unit:=wdCharacter, Count:=iCount
End Sub


The problem with the code now it's adding the brackets for the last line only do you know or if it's possible to help on how I can add to each bold sentence only ?
I would be appreciated for your time and effort

Attachments area
Reply With Quote
  #2  
Old 05-16-2021, 08:15 PM
Guessed's Avatar
Guessed Guessed is offline Automatically Inserting Brackets to EACH selected line Windows 10 Automatically Inserting Brackets to EACH selected line Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

Post a sample document and highlight the bits that you want the brackets on. Your screenshot shows bold headings and bold inside paragraphs as well as the bolded list.

If the parts you want bracketed are autoonumbered the code might be a bit complex
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 05-16-2021, 09:57 PM
ar100j ar100j is offline Automatically Inserting Brackets to EACH selected line Windows 10 Automatically Inserting Brackets to EACH selected line Office 2019
Novice
Automatically Inserting Brackets to EACH selected line
 
Join Date: May 2021
Posts: 3
ar100j is on a distinguished road
Default

Thanks for your fast feedback

please check again the photo with the highlighted parts

I don't needed for header or lists or number just the normal text
Attached Images
File Type: jpg 000793-New Microsoft Word Document.docx.jpg (130.9 KB, 13 views)
Reply With Quote
  #4  
Old 05-16-2021, 10:05 PM
Guessed's Avatar
Guessed Guessed is offline Automatically Inserting Brackets to EACH selected line Windows 10 Automatically Inserting Brackets to EACH selected line Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

This will may get your 'headings' as well if you didn't format them with built-in styles.
Code:
Sub BracketsOnBold()
  With Selection.Find
    .ClearFormatting
    .Font.Bold = True
    .ParagraphFormat.OutlineLevel = wdOutlineLevelBodyText  'this excludes headings
    .Replacement.ClearFormatting
    .Text = ""
    .Replacement.Text = "[^&]"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 05-16-2021, 10:25 PM
ar100j ar100j is offline Automatically Inserting Brackets to EACH selected line Windows 10 Automatically Inserting Brackets to EACH selected line Office 2019
Novice
Automatically Inserting Brackets to EACH selected line
 
Join Date: May 2021
Posts: 3
ar100j is on a distinguished road
Default

it works perfect no need for anything more than this, really appreciate your effort and your works thanks a lot sir you saved lots of time for me
Reply With Quote
  #6  
Old 05-17-2021, 07:30 PM
macropod's Avatar
macropod macropod is offline Automatically Inserting Brackets to EACH selected line Windows 10 Automatically Inserting Brackets to EACH selected line Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Cross-posted at: Automatically Inserting Brackets to EACH selected line (Word Doc.) - Microsoft: Office - Tek-Tips
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
macro edit, macro multiple functions

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax for inserting blank line before inserting table and after a line or paragraph SamDsouza Word VBA 8 08-04-2019 11:10 PM
How to move a line to another line that starts with a chain selected in the 1st one? gloub Word VBA 24 03-19-2019 03:12 PM
Automatically Inserting Brackets to EACH selected line find and delet all text within brackets and the brackets themselves wrdy Word 2 08-03-2017 06:55 PM
Automatically Inserting Brackets to EACH selected line macro to add brackets to each line and add single quotes to each word in the line bracketandquotes Word VBA 17 02-16-2015 03:51 PM
Inserting nested brackets in a field code deletes numeration piotrek99 Word 1 11-02-2014 01:15 PM

Other Forums: Access Forums

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