#1
|
|||
|
|||
Macro to convert text to endnote?
Hi, gang.
I have a good number of Word files (Word 2000) containing entries with source citations enclosed between brackets, like this: <Brady, S.F.Independent, 3-24-92> Over time, however, I've accumulated enough such citations, that it sort of hampers the ability to visually read the text, so I'd like to convert those "in-line" citations into endnotes. I've been trying (unsuccessfully) for a while now to figure out how to write a macro that would do the following: * Search for all instances of text contained between a "<" and a ">". * Allow for a "Replace" or "Find Next" option (as in Search/Replace) so that I could choose to skip a particular instance if desired and move on the next find. * If choose NOT to skip ("Find Next"), then strip out the "<" and ">", and then convert the remaining text (what was originally between the "< >") into an endnote. This would clean up the text itself, while preserving the specific citations and their connection to the particular text in the doc, nicely tucked into the endnote section. Any ideas? |
#2
|
||||
|
||||
Cross-posted at: http://social.technet.microsoft.com/...f-27ff46b3f340
Orifacious: For cross-posting etiquette, please read: http://www.excelguru.ca/node/7
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Sorry for the cross-post
Didn't understand that ethic sitch; do now.
|
#4
|
||||
|
||||
Hi Orifacious,
Try: Code:
Sub MakeEndNotes() Dim RngSel As Range, RngFnd As Range, StrNote As String Application.ScreenUpdating = False With Selection Set RngSel = .Range With .Find .ClearFormatting .Replacement.ClearFormatting .MatchWildcards = True .Wrap = wdFindContinue .Forward = True .Text = "\<[!\>\<]{1,}\>" Do While .Execute = True Set RngFnd = ActiveDocument.Range(Start:=Selection.Start, End:=Selection.End) StrNote = Mid(RngFnd.Text, 2, Len(RngFnd.Text) - 2) ActiveDocument.Endnotes.Add RngFnd, , StrNote RngFnd.Text = vbNullString Loop End With End With RngSel.Select Set RngFnd = Nothing: Set RngSel = Nothing Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] Last edited by macropod; 06-02-2011 at 06:49 PM. |
#5
|
|||
|
|||
Wow! That works fast and neat. Thanks!
Is there any way to make it hi-light the placemarker for the endnote in the main text? I find those little guys hard to see in a big text file, and usually hi-light them yellow. One minor problem is that the macro doesn't pause at each found instance (and give the option to perform the conversion or else move to the next found instance), but just zips right through the whole file like a bullet. I have occasionally used those same brackets ( "< >" ) to indicate other things as well --I know, sloppy, and a bad symbol to use anyway, since it's prone to be interpreted in macros as a find function switch rather than an actual character-- so it would be nice if I could pause at each find and decide on a per case basis to perform the endnote conversion or not. But believe me, it's much less work pulling the errant misconversions back out of the endnotes than hunting and converting each one, so really thanks! Don't think I could ever have figged that one out. |
#6
|
||||
|
||||
Quote:
Quote:
Rather than complicating the macro further, you could use a wildcard Find/Replace with: Find = (\<)([!\>\<]{1,})(\>) Replace = {\2} to change the '<*>' strings you don't want converted to endnotes to '{*}' strings (use something other than '{' and '}' if those characters are already in use), stepping through the Find/Replace process. Then run the macro. If you want to get the '<*>' strings back again afterwards, simply reverse the Find/replace process: Find = (\{)([!\}\{]{1,})(\}) Replace = <\2> and this time you won't need to step through.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Excellent advice, and I thank you!
Actually, I felt retroactively dumb for having come back with the bit about how to hi-light an endnote reference, since I do know how to format a style or two; but had my head wrapped up in the macro at the mome. I figured that one out as soon as I'd backed off of posting the message. But the search & replace is helpful, and rounds out my need, as it were, so thanks again! |
#8
|
|||
|
|||
the macro gives error 5560 whats the problem?
I run the macro in word and i mark a word inside brackets <test>. But take error 5560 run time error visual basic. And says the text in find contains a wrong expression.
|
#9
|
||||
|
||||
That suggests you may be working with a Windows regional setting that doesn't accept some of the english-language expressions. Try changing:
.Text = "\<[!\>\<]{1,}\>" to: .Text = "\<[!\>\<]{1;}\>"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#10
|
|||
|
|||
Quote:
But let me ask you something and if you know tell me because im new on the computing. 1.I wonder if i can replace the <> with other characters such us {} or [] is this difficult to chance something like that? 2.Is difficult to change the <> inside brackets text, not to endnote but to plain text without brackets, or the option to delete this text with the brackets together? Anyway, thanks a lot for your apply. |
#11
|
||||
|
||||
Hi Saints,
You can certainly change the '<' and '>' characters to something else - they're only in the code to meet the OP's requirements. Simply deleting them would be problematic, because the code is written to look for the longest possible string not containing those characters. I'm not sure what you mean with your second question. If all you want to do is to delete the '<' and '>' characters (and, perhaps, remove character formatting from the intervening text), you wouldn't need this kind of macro - a wildcard Find/Replace would do the job, where: Find = \<([!\>\<]{1;})\> Replace = \1 and you set the Replacement font style to 'regular' with no 'effects'.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#12
|
|||
|
|||
Quote:
|
#13
|
|||
|
|||
Quote:
|
#14
|
||||
|
||||
That's a fairly trivial change:
1. Change the macro's name; 2. Change - ActiveDocument.Endnotes.Add RngFnd, , StrNote to - ActiveDocument.Footnotes.Add RngFnd, , StrNote
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#15
|
|||
|
|||
Thanks a lot
Thats working excellent thanks a lot.
|
Tags |
convert text to endnote, macro |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Creating macro to convert/print to pdf | shabbaranks | Word | 3 | 05-18-2011 08:59 AM |
Cross-reference endnote text | smed | Word | 3 | 01-14-2011 03:34 PM |
convert html to text at opening | etfjr | Word | 0 | 12-13-2010 11:14 AM |
Convert Number to Text | devcon | Word | 0 | 07-10-2010 01:16 AM |
Convert Dollar amount to text | GeorgeLawshe | Word | 0 | 03-07-2010 10:17 PM |