Our ex­pert an­swers your soft­ware queries

Computer Shopper - - CONTENTS -

I’m writ­ing my dis­ser­ta­tion in Word 2010, and in­cluded ci­ta­tions in the text en­closed in an­gle brack­ets, so they ap­pear:

<Bloggs, F, Jour­nal of Ma­jorolo­gies, 2015>

I’ve now been told they should be in­cluded as end­notes rather than be­ing within the text. There are hun­dreds of them scat­tered through the text; is there a way to con­vert them au­to­mat­i­cally to end­notes, ei­ther us­ing some sort of Find and Re­place that’s more so­phis­ti­cated than I can come up with, or us­ing a macro? Mary Phillip­son

The eas­i­est way to do this is with a macro. All it has to do is to look through the text:

.Text = "\<[!\>\<]{1,}\>"

The con­fus­ing bit of the macro is the part that sets up the text to search for. The prob­lem is that in Word's Find and Re­place, the char­ac­ters < and > are used to let you find the be­gin­nings and ends of words re­spec­tively. So in ‘nor­mal’ find and re­place oper­a­tions, you can search for the be­gin­ning of a word by us­ing the < char­ac­ter, so <(in­ter) finds ‘in­ter­est­ing’ and ‘in­ter­cept’, but not ‘splin­tered’, while (in)> finds ‘in’ and ‘within’, but not ‘in­ter­est­ing’.

You want to look for text that’s sur­rounded by those char­ac­ters, so you have to use a tech­nique called es­cap­ing. If you want to search for a char­ac­ter that’s de­fined as a wild­card, you type a back­slash (\) be­fore the char­ac­ter.

So the start of your text to search for el­e­ment is:


The next part of the ex­pres­sion tells Word that the text you’re try­ing to match next should have any amount of text, end­ing with a clos­ing an­gle bracket. You only want to find text that has a sin­gle clos­ing an­gle bracket. The part of the ex­pres­sion that tells Word this is:


The curly brack­ets {} are used to say how many oc­cur­rences of a let­ter or text are ac­cept­able – in our case, only one. The fi­nal part of the ex­pres­sion is the mid­dle bit:


You can tell Word to look for any one of the char­ac­ters us­ing the square brack­ets, [], with the char­ac­ters you’re search­ing for in the mid­dle, so [kay] would find any­thing with the text k, a or y. You can spec­ify any char­ac­ter ex­cept those in the square brack­ets by us­ing the ! op­er­a­tor, so [!kay] would find any text ex­cept if it con­tained k, a or y.

What you want is text that starts and ends with < and >, but doesn’t have those char­ac­ters within it. That’s a rather con­vo­luted way of ex­plain­ing to Word that the text pat­tern should be a sim­ple:

<some text but not an­gle brack­ets>

As be­fore, if you want to re­fer to a spe­cial char­ac­ter such as an an­gle bracket, you have to ‘es­cape’ it us­ing the \, re­sult­ing in the fi­nal full ex­pres­sion of:

.Text = "\<[!\>\<]{1,}\>"

What the macro does is se­lect the en­tire ac­tive doc­u­ment. A Find operation is then started, look­ing for sec­tions of text sur­rounded by an­gle brack­ets. When a match is found, the vari­able RngFound is set to point to that part of the doc­u­ment. A copy of the text is then placed in the vari­able StrMakeNote, apart ⬅ You can con­vert text to end­notes us­ing a macro in Word from the two brack­ets. This is done us­ing the Mid func­tion in the line:

StrMakeNote = Mid(RngFound. Text, 2, Len(RngFound.Text) - 2)

This says take the mid­dle of the text, start­ing at po­si­tion 2, and take as many char­ac­ters as the length of the text mi­nus two char­ac­ters, get­ting you the text with­out the brack­ets. An end­note is then in­serted with that text us­ing:

Ac­tiveDoc­u­ment.End­notes.Add RngFound, , StrMakeNote

The text in the range RngFound is set to be the null string, so re­mov­ing the text and the an­gle brack­ets, and the macro con­tin­ues the Find operation.

Sub MakeEndNotes() Dim RngFound As Range, StrMakeNote As String With Ac­tiveDoc­u­ment .Se­lect With Se­lec­tion.Find .ClearFor­mat­ting .Re­place­ment. Clear For­mat­ting .MatchWild­cards = True .Wrap = wdFindCon­tinue .For­ward = True .Text = "\<[!\>\<]{1,}\>" Do While .Ex­e­cute = True Set RngFound = Ac­tiveDoc­u­ment. Range( Start := Se­lec­tion. Start, End := Se­lec­tion. End) StrMakeNote = Mid( RngFound.T ext ,2, Len( RngFound.T ext )-2) Ac­tive Doc­u­ment. End notes. Add RngFound, , StrMakeNote RngFound.Text = vbNul­lString Loop End With End With End Sub

Newspapers in English

Newspapers from UK

© PressReader. All rights reserved.