PDA

View Full Version : Modifying a macro in Word



Pwyll2
06-14-2014, 03:24 AM
Hello !

I have got a macro (kindly written by members of this forum) that is meant to change the order of text paragraphs, according to the beginning of each of their lines (each line of each paragraph starts with the same markers, in the same order).
I’d like to modify that macro to change the order of the lines of my paragraphs (I’d like to reverse the order of 2 elements actually)

Here is my macro :


Sub XmlToLp3MettreMarqueursDansOrdreLp()
Application.ScreenUpdating = False
Dim strTags As String, i As Long
strTags = "sfx|xv,xinfor|xfon"
With ActiveDocument.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
.Text = "^13"
.Replacement.Text = "^13^p"
.Execute Replace:=wdReplaceAll
For i = 0 To UBound(Split(strTags, ","))
.Text = "(\\" & Split(Split(strTags, ",")(i), "|")(0) & "*)(\\" & Split(Split(strTags, ",")(i), "|")(1) & "*^13)"
.Replacement.Text = "\2\1"
.Execute Replace:=wdReplaceAll
Next
.Text = "^13^13"
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub


Here is a sample paragraph before using any macro :


\sfx PYK-29083-MK-0310.mp3
\xinfor M.K. (1924)
\xbrloc Veleur ket alies.
\xfon
\xv Ne weler ket alies.
\xtrad On ne le voit pas souvent.
\lt
\nt


Here is a sample paragraph after the current macro (that I pasted above) :


\xv Ne weler ket alies.
\sfx PYK-29083-MK-0310.mp3
\xfon
\xinfor M.K. (1924)
\xbrloc Veleur ket alies.
\xtrad On ne le voit pas souvent.
\lt
\nt


and here is the paragraph as I’d like it to become, instead of the very preceding one :


\xbrloc Veleur ket alies.
\sfx PYK-29083-MK-0310.mp3
\xfon
\xinfor M.K. (1924)
\xv Ne weler ket alies.
\xtrad On ne le voit pas souvent.
\lt
\nt

In comparison to the current macro, the new macro will just need to reverse the order of the lines that start with \xbrloc and \xv.
If you could modify my macro so that it does this, it would be awesome ! Must be simple but I don’t understand anything in VBA so I can’t do it myself :(

Thanks a lot in advance !