VBA处理法
'* +++++++++++++++++++++++++++++
'* Created By I LOVE YOU WORD!@ExcelHome 2006-3-4 17:35:16
'仅测试于System: Windows NT Word: 11.0 Language: 2052
'№ 0027^The Code CopyIn [ThisDocument-ThisDocument]^'
'* -----------------------------
Option Explicit
Sub RepExample()
'处理回旋数据,如ABCDEFGGFEDCBA
Dim myString As String, lngStart As Long, lngEnd As Long, lngHalf As Long
Dim myRange1 As Range, aWord As Range, myRange2 As Range
Dim intLenth As Integer, strWord As String
With ActiveDocument
For Each aWord In .Words '遍历词组,注意你的词组,主体应为数字和英文
With aWord
strWord = .Text '文本内容
intLenth = VBA.Len(strWord) '词组长度
lngStart = .Start '起点位置
lngEnd = .End '终点位置
End With
If intLenth Mod 2 = 0 Then '回旋词组必定为双数长度
lngHalf = (lngStart + lngEnd) / 2 '折点位置
Set myRange1 = .Range(lngStart, lngHalf) '前半部分
Set myRange2 = .Range(lngHalf, lngEnd) '后半部分
If VBA.StrReverse(myRange2.Text) = myRange1.Text Then '如果后半部分倒过来等同于前半部分
myString = myString & myRange1.Text '内存中累加前半部分
Else
myString = myString & strWord '累加
End If
Else
myString = myString & strWord '累加
End If
Next
.Content.Text = myString '重写文档内容
End With
End Sub
[此贴子已经被作者于2006-3-4 17:38:25编辑过] |