Reverse large files

N

Nomey

Dear all,

Can someone explain why the following code doesn't invert a selection of 60,000 words. Only a small part at the end of the doc is inverted.

Sub ReverseSelection02()
Dim strA As String
If Selection.Type = wdNoSelection Then
MsgBox ("There is no selection.")
Else
strA = StrReverse(Selection)
Selection.TypeText (strA)
End If
End Sub

I'm asking this because I would like to invert a large document with occasional italic and bold formatting, as well as small caps. Is there another method to the text of docs like this - preserving character formatting? Given the file size, it has to be rather quick.

Chau
Nomey
 
J

Jezebel

Your method does indeed reverse all the text of a document (on my test,
anyway). But it won't produce the result you want: TypeText works with plain
text only, so this method necessarily discards all formatting; on top of
which it scrambles the document by reversing the CR/LF sequences at the ends
of paragraphs, not to mention the hideous mess it makes of tables.

Perhaps you could explain your objective in a little more detail: do you
really want the last character of the document to become the first
character, the penultimate to become the second, the antepenultimate the
third, and so on? or do you want to reverse the order of characters within
each paragraph? Do you want each character to retain its formatting, or each
character position?
 
N

Nomey

Hi Jezebel,

That is exactly what I would like to achieve: to revert the order of characters within a selection, whether that is just a single word, a couple of sentences/paragraphs or all text in a document. And without losing character formatting, such as bold, etcetera.

My Word version is XP 2002.

Kind regards,
Shirley Nomey
 
J

Jezebel

You still need to explain your needs further. If you start with the string
ABCDE and B is in bold, and you end up with EDCBA, do you want B or D to be
bold? (ie is it the character or the character *position* that retains the
formatting?) What do you want to do about styles and paragraph formatting?

Whatever your spec, this is not going to be easy to program, and it
certainly isn't going to be quick to run. To preserve character formatting,
you're going to have to work character by character; and to avoid scrambling
your document, you're going to have check for things that you don't want to
reverse, like field names, end of table marks, etc.
 
N

Nomey

Hi Hezebel,

If possible, ABCDE with B and D bold, should be EDCBA with B and D bold. The documents on which I want to run the macro don't have paragraph formatting, nor footnotes, fields, tables or any other special feature. I had no idea that would be such a difficult task and such a time consuming routine when I first started to develop my test macro.

For the time being, I would settle for a quick macro that flips an entire text of 60,000 words without keeping the formatting. My test macro seems to *delete* large parts of the document, retaining only a small portion, which is reversed correctly.

How's that possible? Does the StrReverse() function have built-in lrestrictions, like length, not being able to cross hard returns or hard page breaks, or whatever?

Shirley Nomey
 
J

Jezebel

You missed the point of my ABCDE query: if B (only) is bold in the original,
what character should be bold in the reversal - B or D?

As for strReverse failing on your document: no there is no restriction on
length that I'm aware of. My guess is that your document contains some
character sequence which, when reversed, represents a document corruption. I
just tried it on a document of mine that was originally some 35 pages -- I
got the whole lot in reversal, but completely scrambled as a document: a
whole mess of chinese characters appeared, and tables disappeared: the table
character markers must have ended up *somewhere* ...
 

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