Search and switch textorder in Word

J

Jornebof

Hi!
I need to replace the textorder of some lines in a large document, like this:

Fixedtext:xxx

where Fixedtext is fixed and xxx is any number of any characters should be
switched to look like this

xxxFixedtext

Is there anyone who can help me?
Thank you in advance!!
Fredrik Jornebo
 
G

Graham Mayor

Does the line of text containing the fixed text end in a paragraph mark?
In which case the replace function will work Replace
(Fixedtext):(*)(^13)
with
\2\1\3

or with a macro you could use (say)

Dim oPara As Range
Dim sText() As String
For i = 1 To ActiveDocument.Paragraphs.Count
Set oPara = ActiveDocument.Paragraphs(i).Range
oPara.End = oPara.End - 1
If InStr(1, oPara.Text, "Fixedtext:") Then
sText = Split(oPara, ":")
oPara.Text = sText(1) & sText(0)
End If
Next i

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
J

Jornebof

Hi Graham!

Thank you so much for your fast answer!

I tried the replace function that you mentioned but it didn't work. The text
in the (*) section just didn't move. I use Word 2003 is this a known issue?
If i use ([a-z]{1,}) it worked beautifully, but the problem is that the text
I want to move is in chinese. So I tried the macro you sent me. It worked in
a small file. But the file I want to change text in is a 33MB txt-file and
the text is to be replaced around 6000 times. It has been running for 12
hours now and is still not finished. Is this normal?

Best regards,
Fredrik
 
G

Graham Mayor

Unfortunately your original message made no mention of Chinese! Had it does
so I would not have attempted to offer a solution. I based my reply on the
string that you quoted. I regret I don't know anything about Chinese nor the
problems you are likely to encounter, but 12 hours to parse 6000 paragraphs
seems somewhat excessive. I guess that the macro is locked into a loop.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Hi Graham!

Thank you so much for your fast answer!

I tried the replace function that you mentioned but it didn't work.
The text in the (*) section just didn't move. I use Word 2003 is this
a known issue? If i use ([a-z]{1,}) it worked beautifully, but the
problem is that the text I want to move is in chinese. So I tried the
macro you sent me. It worked in a small file. But the file I want to
change text in is a 33MB txt-file and the text is to be replaced
around 6000 times. It has been running for 12 hours now and is still
not finished. Is this normal?

Best regards,
Fredrik

Graham Mayor said:
Does the line of text containing the fixed text end in a paragraph
mark? In which case the replace function will work Replace
(Fixedtext):(*)(^13)
with
\2\1\3

or with a macro you could use (say)

Dim oPara As Range
Dim sText() As String
For i = 1 To ActiveDocument.Paragraphs.Count
Set oPara = ActiveDocument.Paragraphs(i).Range
oPara.End = oPara.End - 1
If InStr(1, oPara.Text, "Fixedtext:") Then
sText = Split(oPara, ":")
oPara.Text = sText(1) & sText(0)
End If
Next i

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

Klaus Linke

Graham Mayor said:
Unfortunately your original message made no mention of Chinese! Had it
does so I would not have attempted to offer a solution. I based my reply
on the string that you quoted. I regret I don't know anything about
Chinese nor the problems you are likely to encounter, but 12 hours to
parse 6000 paragraphs seems somewhat excessive. I guess that the macro is
locked into a loop.


One thing you could try is to replace (*) with ([!^13]@).
The * joker potentially matches lots and lots of text, which may be the
cause of the slowness.
[!^13]@ matches arbitrary text too, but at most one paragraph, which should
suffice for your replacement.

Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top