CobolDrudge
New Member
This is a VBA question for Word, not Excel. I hope that’s OK.
I have a large Word document which needs an edit. I’m pretty sure it requires VBA because of a boolean condition. Here is a sample of the file (4 paragraphs; a couple of non-ascii characters not showing properly):
Viola riviniana, common dog-violet {het bleeksporig bosviooltje}; large square sepal appendages >1.5mm, spur curved up, blunt, notched, paler, much branched purple veins esp. lower petal
V. reichenbachiana, early dog-violet {het donkersporig bosviooltje}; sepal appendages <1.5mm, spur straight, pointed, unnotched, violet, darker, upper petals cf rabbit, veins on lower unbranched
V. odorata, sweet violet {de maarts viooltje}; closely downy, sepals blunt, broad glossy lvs, rooting runners, fragrant, fl dark violet, white, other colours; vc
V. palustris, marsh violet {het moerasviooltje}; lvs reniform, 1-4cm wide, fls 10-15mm wide, blunt petals with dark purple veins, blunt spurs
And here is what I need to change it to:
Viola riviniana, common dog-violet {bleeksporig bosviooltje (het)}; large square sepal appendages >1.5mm, spur curved up, blunt, notched, paler, much branched purple veins esp. lower petal
V. reichenbachiana, early dog-violet {donkersporig bosviooltje (het)}; sepal appendages <1.5mm, spur straight, pointed, unnotched, violet, darker, upper petals cf rabbit, veins on lower unbranched
V. odorata, sweet violet {de maarts viooltje}; closely downy, sepals blunt, broad glossy lvs, rooting runners, fragrant, fl dark violet, white, other colours; vc
V. palustris, marsh violet {moerasviooltje (het)}; lvs reniform, 1-4cm wide, fls 10-15mm wide, blunt petals with dark purple veins, blunt spurs
All the action is in the curly brackets which occur as a pair either once or not at all per paragraph. The job is to move the word ‘het’ if it occurs directly after the opening curly bracket, to behind the closing bracket, surrounding it with round brackets. In other words, the five characters ‘{het ‘ become ‘{‘ and ‘}’ becomes ‘ (het)}’ (note added leading space)
In the third paragraph in the sample there is no change applied because we have ‘de’ instead of ‘het’.
I have a notion how to do the looping. Going though the paragraphs will be something like
For i = 1 to ActiveDocument,Paragraphs.Count
.
Next i
And within that I can loop through the words with something along the lines
For j = 1 to ActiveDocument.Paragraphs(i).Range.Words.Count
.
Next j
- but I’m not at all sure how to code the text manipulation and would appreciate help. I see the main problem as being that ‘{het’ is a single item in the Words collection because it has a space on either side, but ‘}’ is not a word because it never has a space on either side.
I have a large Word document which needs an edit. I’m pretty sure it requires VBA because of a boolean condition. Here is a sample of the file (4 paragraphs; a couple of non-ascii characters not showing properly):
Viola riviniana, common dog-violet {het bleeksporig bosviooltje}; large square sepal appendages >1.5mm, spur curved up, blunt, notched, paler, much branched purple veins esp. lower petal
V. reichenbachiana, early dog-violet {het donkersporig bosviooltje}; sepal appendages <1.5mm, spur straight, pointed, unnotched, violet, darker, upper petals cf rabbit, veins on lower unbranched
V. odorata, sweet violet {de maarts viooltje}; closely downy, sepals blunt, broad glossy lvs, rooting runners, fragrant, fl dark violet, white, other colours; vc
V. palustris, marsh violet {het moerasviooltje}; lvs reniform, 1-4cm wide, fls 10-15mm wide, blunt petals with dark purple veins, blunt spurs
And here is what I need to change it to:
Viola riviniana, common dog-violet {bleeksporig bosviooltje (het)}; large square sepal appendages >1.5mm, spur curved up, blunt, notched, paler, much branched purple veins esp. lower petal
V. reichenbachiana, early dog-violet {donkersporig bosviooltje (het)}; sepal appendages <1.5mm, spur straight, pointed, unnotched, violet, darker, upper petals cf rabbit, veins on lower unbranched
V. odorata, sweet violet {de maarts viooltje}; closely downy, sepals blunt, broad glossy lvs, rooting runners, fragrant, fl dark violet, white, other colours; vc
V. palustris, marsh violet {moerasviooltje (het)}; lvs reniform, 1-4cm wide, fls 10-15mm wide, blunt petals with dark purple veins, blunt spurs
All the action is in the curly brackets which occur as a pair either once or not at all per paragraph. The job is to move the word ‘het’ if it occurs directly after the opening curly bracket, to behind the closing bracket, surrounding it with round brackets. In other words, the five characters ‘{het ‘ become ‘{‘ and ‘}’ becomes ‘ (het)}’ (note added leading space)
In the third paragraph in the sample there is no change applied because we have ‘de’ instead of ‘het’.
I have a notion how to do the looping. Going though the paragraphs will be something like
For i = 1 to ActiveDocument,Paragraphs.Count
.
Next i
And within that I can loop through the words with something along the lines
For j = 1 to ActiveDocument.Paragraphs(i).Range.Words.Count
.
Next j
- but I’m not at all sure how to code the text manipulation and would appreciate help. I see the main problem as being that ‘{het’ is a single item in the Words collection because it has a space on either side, but ‘}’ is not a word because it never has a space on either side.