![]() |
#1
|
|||
|
|||
![]()
Hello,
I have to modify more than 700 biblio references to put them into footnotes in a document of hundred pages. So, I'm looking at VBA Word, but I 'm almost totally newbie. Documentation seems hard to find, especially as regards to basis (object model, etc.). Here it is what I've tried and the major problem I'm facing with described after. The sketch of the code used is as follows: Code:
Sub Replace_ref_1() ' Definition of all variables ' ... Set docRange = ActiveDocument.Range ' Definition of the Regex needed With regEx ... ' Definition with required options etc. => OK End With Options.Overtype = False ' Insert and not delete ActiveDocument.TrackRevisions = False ' Out of tracking changes mode ' Regex matchs Set regFound = regEx.Execute(docRange) ' Loop over results, going by the last (highest index) For cpt = regFound.Count To 1 Step -1 refText = regFound(cpt - 1) Selection.SetRange Start:=regFound.Item(cpt - 1).FirstIndex, End:=regFound.Item(cpt - 1).FirstIndex Selection.Collapse Direction:=wdCollapseStart Selection.Footnotes.Add Range:=Selection.Range, Text:=LTrim(refText) Next cpt MsgBox "Number of matchs processed = " & regFound.Count End Sub I meet the following problem: numbers (mark) of footnotes are not inserted at the correct place. In general, a few to some dozens of characters before expected. I thought it was due to the fact that adding footnotes implied adding characters to the text, and so the index couldn't be OK. That's why I tried processing from the last to the first: cf. "downto" loop. (I checked before this try that matches were in increasing index by writing them in a file.) But this is not better... I noticed also that for a portion of text with only 3 matches, it's OK. But as soon as the text is too long, it doesn't work, either with the first or the last matches. I also noticed that it is better if I remove the summary (which lies at the begining), but even with that "trick", for a portion of doc with 133 matches, only the 57 first are OK, and all that follow are shifted (without any change in format between the 57th and 58th match...). I guess there may be a problem in my understanding of index, or, moreover, in the portion of text included in the indexes... I would be glad if someone could help me about that. Thanks ![]() |
Tags |
regex, replace |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
abdan | Word VBA | 3 | 01-18-2019 09:38 PM |
How to compare 2 Excel sheets for 100+ matches? | dylansmith | Excel | 5 | 05-22-2017 09:09 PM |
Macro help regex | subspace3 | Word VBA | 1 | 10-15-2014 09:53 AM |
![]() |
gasyoun | Word VBA | 9 | 04-12-2013 04:15 PM |
Regex in Word: Replaced strings are in disorder | chgeiselmann | Word | 0 | 04-26-2009 11:33 AM |