[mso] Word [2000]: Macro to reverse text L-R

  • From: "Andrew Kendon" <kendon@xxxxxxxxxxxx>
  • To: "Mso@Freelists. Org" <mso@xxxxxxxxxxxxx>
  • Date: Thu, 10 Jun 2004 08:45:19 +0100

Could some VBA-savvy person please help me with a macro to reverse text
(Left-to-Right, character by character on a Line basis) in Word.

The effect I want is that every line is reversed
left to right, as in this example:

desrever si enil yreve taht si tnaw I tceffe ehT
:elpmaxe siht ni sa ,thgir ot tfel

I found a code snippet and I understand how it works, but I haven't the
first idea how to use it in a Sub (if that's what has to be done) to work
the way I want.  The snippet is:

Public Function ReverseString(ByVal InputString As String) _
  As String

Dim lLen As Long, lCtr As Long
Dim sChar As String
Dim sAns As String

lLen = Len(InputString)
For lCtr = lLen To 1 Step -1
    sChar = Mid(InputString, lCtr, 1)
    sAns = sAns & sChar
Next

ReverseString = sAns

End Function

I suppose that what I need the sub to do is:
Select each line in turn until the end of the document
Feed it as a parameter to ReverseString
Replace the line with ReverseString (which now contains the reversed text)
Loop

(Once upon a time I used to know how to write pseudo-code). I could probably
jog the brain cells to produce something that works on a text file in Basic
or Pascal but I never kept up with the new commands required by Windows or
Word, so, though I know what ReverseString does as a function, I am at a
loss to wrap it up so it does anything useful!  I'm not even sure whether it
needs to be declared Public.

TIA

Andrew Kendon
(IT Trainer)
----------------------------------
Skills Training UK Ltd
Cherry Hinton Hall Learning Centre
Cherry Hinton Road
CAMBRIDGE CB1 8DW
----------------------------------
Tel.: 01223 458257
Mobile: 07815 301113
----------------------------------

*************************************************************
You are receiving this mail because you subscribed to mso@xxxxxxxxxxxxx or 
MicrosoftOffice@xxxxxxxxxxxxxxxx

To send mail to the group, simply address it to mso@xxxxxxxxxxxxx

To Unsubscribe from this group, send an email to 
mso-request@xxxxxxxxxxxxx with the word "unsubscribe" (without the quotes) in 
the subject line.

Or, visit the group's homepage and use the dropdown menu.  This will also allow 
you to change your email settings to digest or vacation (no mail).
//www.freelists.org/webpage/mso

To be able to use the files section for sharing files with the group, send a 
request to mso-moderators@xxxxxxxxxxxxx and you will be sent an invitation with 
instructions.  Once you are a member of the files group, you can go here to 
upload/download files:
http://www.smartgroups.com/vault/msofiles
*************************************************************

Other related posts: