#1
|
|||
|
|||
Add a return between two square brackets
I have multiple instances of square brackets that I need to add a return...
Can this be done with a macro? Before- [Proverbs 4:26 NASB] [26] Watch the path of your feet And all your ways will be established. [Proverbs 18:19 NASB] [19] A brother offended is harder to be won than a strong city, And contentions are like the bars of a citadel. [Proverbs 11:29 NASB] [29] He who troubles his own house will inherit wind, And the foolish will be servant to the wisehearted. After- [Proverbs 4:26 NASB] [26] Watch the path of your feet And all your ways will be established. [Proverbs 18:19 NASB] [19] A brother offended is harder to be won than a strong city, And contentions are like the bars of a citadel. [Proverbs 11:29 NASB] [29] He who troubles his own house will inherit wind, And the foolish will be servant to the wisehearted. |
#2
|
|||
|
|||
You gave no feedback about the last code you received so why should anyone help you this time.
|
#3
|
||||
|
||||
@slaycock
As your (unfriendly) remark might be understandable in some cases (and perhaps even correct in this case), I would suggest you take some time to investigate the person you are offensive with in the future Jeff has been a great help on this forum ( I know it mostly from Excel and other forums), providing good answers and also getting more than his share of OP's not giving any feedback, not thanking him, etc.. (I know the feeling too after more than 10k posts on various forums...) AFAIK, he never made any remarks in the sense you did although I can easily imagine he has been frustrated many times. I do not know how well you are acquainted with free forums, but in this case you seem to be heavily overreacting and possibly hurting someone who is a great help. May I suggest, in the future, that you PM the member to understand why he gave no feedback? Cheers
__________________
Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post |
#4
|
|||
|
|||
I stand corrected.
The answer John is looking for is to use Find and Replace with wildcards Search for ([\]])([\[]) and replace with \1^p\1. It looks complicated because both [ and ] have to be escaped by preceding them with the \ The replace box refers to fiels which are defined by everything between 9 and 0. The search has two such fields. the ^p is the replace special symbol for a pararaph marker/ NOTE that ^p cannot be used in the search box, you need to use ^013 instead. If you were doing this by a macro then .find.text="([\]])([\[])" .replacement.text="\1^p\2" |
#5
|
|||
|
|||
Thank you both Pecoflyer and slaycock...
@slaycock, I'm stepping out right now with the grandkids to enjoy the day, so I will test this later with the appropriate feedback. |
#6
|
|||
|
|||
Hi slaycock,
Didn't quite get the results I expected. First, it does not handle the space between the open and close square bracket. I removed the space and the f/r did run, but was hoping the find and replace could pick up the ] space [ pattern. However, by removing the space, one of the open square brackets gets changed to a close square bracket on the new line instead of the results in post #1. [Proverbs 4:26 NASB] ]26] Watch the path of your feet And all your ways will be established. [Proverbs 18:19 NASB] ]19] A brother offended is harder to be won than a strong city, And contentions are like the bars of a citadel. [Proverbs 11:29 NASB] ]29] He who troubles his own house will inherit wind, And the foolish will be servant to the wisehearted. |
#7
|
|||
|
|||
My Apologies there is a typo in the first replace text (That's happening a lot at the moment as I have a new keyboard)
\1^p\1 should read \1^p\2 which I did get right further down the page. My old eyes missed the space between the ] and [ The revised search would be ([\]])(*)([\[]) Personally I find the search text quite hard to scan, particularly on my hi res monitor where the search and replace dialog box is tiny. So on reflection an easier to read version would have been ([^091])(*)([^093]) where 091 and 093 are the decimal ascii codes for [ and ]. You can get more information on find and replace using wildcards by clicking the ? on the find and replace dialog box and first looking under Search by using wildcards and then Find and replace text by using regular expressions (Advanced) |
#8
|
|||
|
|||
Thanks slaycock for the additional help...
Using... Find What: ([^091])(*)([^093]) >> Use Wildcard checked Replace: \1^p\2 I get six replacement where I would only expect three The following is what is returned... [ Colossians 3:19 NASB [ 19 Husbands, love your wives and do not be embittered against them. [ Ephesians 3:21 NASB [ 21 to Him be the glory in the church and in Christ Jesus to all generations forever and ever. Amen. [ Ephesians 5:33 NASB [ 33 Nevertheless, each individual among you also is to love his own wife even as himself, and the wife must see to it that she respects her husband. Is it possible to just look for the [ followed by a number and generate the return just before that string? |
#9
|
|||
|
|||
What you are seeing is the ongoing demonstration of my lack of checking due to haste (I'm actually working at home this weekend fighting a deadline).
What has happened is that we have two errors. One in the find field and one in the replace field. In the find field we have the ][ the wrong way round. The find field should be ([^093])(*)([^091] not ([^091])(*)([^093] The error in the replace field comes adding the (*) to the search text. We now have three fields defined by () (Smacks head on wall several times because checking back I can see that my attempt at () in our earlier discussion came out as 9 0. This is because my new keyboard has the number and symbols the wrong way round so my brain types ( but my reflexes type 9 because 9 is above the ( on my new (soon to be ebayed) keyboard) By inserting the (*) your bracket fields have now become fields 1 and 3. By using fields 1 and 2 in the replace text we are replacing the found text with the [ (in this case) and the text found by the (*) (which in this case is everything between the [ and ]) So changing the replace text to \1^p\3 should now get us to the place where you want to be. |
#10
|
|||
|
|||
Now this time it added the return, but deleted the words after the verse number except for the last verse...
Results: [Colossians 3:19 NASB] [19] [Ephesians 3:21 NASB] [21] [Ephesians 5:33 NASB] [33] Nevertheless, each individual among you also is to love his own wife even as himself, and the wife must see to it that she respects her husband. ...and on ([^093])(*)([^091]) I added the last paranthesis |
#11
|
||||
|
||||
It seems to me you could use a ordinary Find/Replace, where:
Find = ]^w[ Replace = ]^p[ or Replace = ]^l[ depending on whether you want to use a paragraph break or line break.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#12
|
|||
|
|||
Thank you Paul, works great.
|
#13
|
|||
|
|||
Quote:
I'l now go stand in the corner until the end of class. And whilst I was doing that I came up with the idea of following up the search and replace using ]^w[ with a second one using just ][ to catch any cases where there is no white space between the ] and [ of interest |
#14
|
|||
|
|||
In the end, this macro does exactly as needed...
Thanks to all... Code:
Sub CleanUpBrakets() Application.ScreenUpdating = False With ActiveDocument.Range.Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .Format = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False .text = "]^w[" .Replacement.text = "]^l[" .Execute Replace:=wdReplaceAll .text = "^w[" .Replacement.text = "^l[" .Execute Replace:=wdReplaceAll End With Application.ScreenUpdating = True End Sub |
#15
|
||||
|
||||
In that case, all you really needed was:
Code:
Sub CleanUpBrakets() Application.ScreenUpdating = False With ActiveDocument.Range.Find .ClearFormatting .Replacement.ClearFormatting .Wrap = wdFindContinue .Format = False .MatchWildcards = False .Text = "^w[" .Replacement.text = "^l[" .Execute Replace:=wdReplaceAll End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Bold numbers between square brackets | jeffreybrown | Word | 4 | 02-13-2017 04:32 PM |
Help with: Replace and reformat numbers inside square brackets | johnbrowny | Word | 1 | 02-13-2016 06:45 PM |
Gray square brackets | waldux | Word | 8 | 09-25-2013 04:14 PM |
square brackets and grey background – why? | eNGiNe | Word | 2 | 11-21-2012 01:06 AM |
Filled square | daksein | Drawing and Graphics | 4 | 06-21-2011 02:36 AM |