A family of Microsoft word processing software products for creating web, email, and print documents.
Hi Pol:
Seriously: create some styles. The macro approach is not going to be stable or reliable, please trust me on this: adding and removing tab stops as direct formatting is likely to lead to document corruption.
If you have a BodyText style, create BodyTextT to be exactly the same but WITH the tab at 7 centimetres. Don't be afraid to change styles in a document, that's what Word expects, and it is built for it.
I don't believe for a moment that the code I suggested is out of your league at all: you are using correctly-typed variables, Arrays are just one step up the ladder from that.
Several of the people posting in here would write it for you if you offered to pay, I would run it up for you myself, except I am right out of time: it's that time of the year.
This is roughly how the store routine would look.
Dim TabArray()
For Each p In Selection.Paragraphs
ReDim TabArray(p.TabStops.Count, 1)
For Each aTab In p.TabStops
With aTab
TabArray(aTab, 0) = .Position
TabArray(aTab, 1) = .Alignment
End With
Next ' aTab
Next ' aParagraph
That declares a "Dynamic" array named TabArray. We do not decide how many rows and columns yet because we don't know how many tabs we have.
Then in ReDim TabArray(p.TabStops.Count, 1) we count the tab stops in the paragraph and set up as many rows in the array as there are tab stops, and two columns, 0 and 1.
Redimming the array has the side benefit of throwing out the previous data.
Then it just walks along the paragraph, storing the position and alignment of each tab stop in a row of the array.
Having done that, you can use your existing routines to inspect the content of the array instead of the paragraph, and delete the tab at 7 centimetres if you find it, add it if you don't.
Then clear ALL of the tabs in the paragraph.
Then iterate through the array adding every tab you find in there to the paragraph.
Then do the next paragraph.
I am sorry, I don't know whether that works or not: and I do not have time to look.
Hope this helps