View Single Post
  #19   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Hebrew / right-to-left text

If you use my last posted version and put the cursor between the M and r of
Mr, or select Mr, Mr Smith is transposed to Rm Smith, which is what was
intended. Neither of the simpler versions I posted yesterday, behave in the
manner you describe. The version posted this morning combines the two so
that a user may put the cursor between or select the characters to be
transposed.

The earlier macro in the thread, the theme of which you have developed, was
concerned more with re-typing a string backwards to attempt to correct a
right to left text that was not correctly formatted from right to left, but
as others have posted, this is not the best way to approach that topic. The
question about the transposition of 2 characters merely evolved from that.


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org




Greg Maxey wrote:
Graham,.

Yes quite correct. I have seen that term so much recently in this
group that it caught

I must be missing the concept. If I type:

Mr Smith goes to Washington

place the cursor between the M and r of Mr then use your method I get:

RmMr Smith goes to Washington

If I select Mr and use my (slightly revised) method I get:

Rm Smith goes to Washington

Sub Transpose()
Dim myRange As Word.Range
Dim bSpace As Boolean
Dim pStr As String
Dim i As Long
Dim oWord As Word.Range
Set myRange = Selection.Range
bSpace = False
If myRange.Words.Count 1 Then
If MsgBox("If you want to transpose the entire selection select yes.
Otherwise only words will be transposed.", vbQuestion + vbYesNo,
"Traspose Entire Phrase") = vbYes Then
pStr = myRange.Text
myRange.Text = StrReverse(pStr)
myRange.Case = wdTitleSentence
Else
For i = 1 To myRange.Words.Count
If myRange.Words(i).Characters.Last = Chr(32) Then bSpace = True
pStr = StrReverse(Trim(myRange.Words(i).Text))
If bSpace Then pStr = pStr & " "
myRange.Words(i).Text = pStr
On Error Resume Next
myRange.Words(i).Case = wdTitleSentence
bSpace = False
Next
End If
Else
pStr = myRange.Text
myRange.Text = StrReverse(pStr)
myRange.Case = wdTitleSentence
End If
End Sub


Graham Mayor wrote:
Let's say 'alternative' rather than 'easier' However for the
additional issue of two transposed characters, it does not address
the capitalisation where the transposed characters begin a sentence.


Greg Maxey wrote:
Graham,

Seems that StrReverse would be an easier method.

Sub Transpose()
Dim myRange As Word.Range
Dim bSpace As Boolean
Dim pStr As String
Dim i As Long
Dim oWord As Word.Range
Set myRange = Selection.Range
bSpace = False
If myRange.Words.Count 1 Then
If MsgBox("If you want to transpose the entire selection select
yes. Ohterwise only words will be transposed.", vbQuestion +
vbYesNo, "Traspose Entire Phrase") = vbYes Then
pStr = myRange.Text
myRange.Text = StrReverse(pStr)
Else
For i = 1 To myRange.Words.Count
If myRange.Words(i).Characters.Last = Chr(32) Then bSpace =
True pStr = StrReverse(Trim(myRange.Words(i).Text))
If bSpace Then pStr = pStr & " "
myRange.Words(i).Text = pStr
bSpace = False
Next
End If
Else
pStr = myRange.Text
myRange.Text = StrReverse(pStr)
End If
End Sub

On Oct 11, 2:02 am, "Graham Mayor"
wrote:
The macro simply re-orders the selected text from end to start as
if you had typed it backwards. I did not envisage using it for long
texts, merely phrases inserted into an English document. However as
I said I have no personal knowledge of left to right languages.

As for transposing two selected characters, that macro would work,
but I suspect the following refinement might suit the task better

Sub Transpose()
Dim sText As String
sText = Selection.Range.Text
If Len(sText) 2 Then
MsgBox "You must select 2 characters!", _
vbCritical, "Transpose Characters"
Exit Sub
End If
If Selection.Range.Characters(1).Case = 1 _
And Selection.Range.Characters(2).Case = 0 Then
Selection.TypeText UCase(Mid(sText, 2, 1)) & _
LCase(Mid(sText, 1, 1))
Else
Selection.TypeText Mid(sText, 2, 1) & _
Mid(sText, 1, 1)
End If
End Sub

--

Graham Mayor - Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org




Peter T. Daniels wrote:
As Tony noted, line breaks will be a problem -- but also, if
there's more than one word, will it reverse each word
independently, or do you need to type your whole clause backward,
last-word-first?

This would of course be most useful to make up for the most
glaring omission in Word's editing tools since the very beginning
(since lots of other DTP apps have it) -- "transpose two
characters"!

On Oct 10, 9:29 am, "Graham Mayor"
wrote:
Peter T. Daniels wrote:
IF you're using a Hebrew font that just puts the letters in the
a-z, A-Z etc. slots, then yes, you have to type backwards.

If the font requires that the text is typed backwards (and I
hasted to add I have no knowledge of right left languages) that
can easily be fixed with a macro that will reverse the order of
selected text eg

Sub ReverseCharacters()
Dim sText As String
sText = Selection.Range.Text
If Len(sText) 2 Then
MsgBox "You must select at least 2 characters!", _
vbCritical, "Reverse Characters"
Exit Sub
End If
For i = Len(sText) To 1 Step -1
Selection.TypeText Mid(sText, i, 1)
Next i
End Sub

http://www.gmayor.com/installing_macro.htm
--

Graham Mayor - Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
- Hide quoted text -

- Show quoted text -