|
楼主 |
发表于 2010-2-11 22:03
|
显示全部楼层
操作系统是中文或者是英文但选择ChinesePRC,则以上代码可简化为:
Sub GetGBKCode()
Dim f
Dim sPos As Single
If Selection.Type = wdSelectionNormal Then
Set myRange = Selection.Range
Selection.Collapse wdCollapseStart
Else
Set myRange = ActiveDocument.Range(Selection.Start, ActiveDocument.Content.End)
End If
sPos = Selection.Start
Selection.Collapse wdCollapseStart
For Each iChar In myRange.Characters
f = ""
iChar = Selection.text
Selection.MoveRight unit:=wdCharacter, Count:=1
a = Hex(AscW(iChar))
If "&H" & a <> &HD Then
f = Hex(Asc(iChar))
Selection.TypeText text:=f
End If
Next
Selection.Start = sPos
Selection.Collapse wdCollapseStart
Exit Sub
ErrHandle:
MsgBox "Error number: " + Str$(Err) + Chr(13) + Error$(Err), 48, m_Title
End Sub |
|