当前位置:编程学习 > VB >>

我编写的字母数字全角半角转换VBA程序(word宏命令),请高手点评

Sub A01_全角变半角()
    Selection.WholeStory
    For i = 0 To 9
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = Chr(-23632 + i)
        .Replacement.Text = Chr(48 + i)
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Next i

        For i = 0 To 25
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = Chr(-23583 + i)
        .Replacement.Text = Chr(97 + i)
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Next i
    
    Selection.Find.Execute Replace:=wdReplaceAll
        For i = 0 To 25
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = Chr(-23615 + i)
        .Replacement.Text = Chr(65 + i)
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Next i
    
    Selection.HomeKey

End Sub



Sub A01_半角变全角()
    Selection.WholeStory
    For i = 0 To 9
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = Chr(48 + i)
        .Replacement.Text = Chr(-23632 + i)
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Next i

    For i = 0 To 25
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = Chr(97 + i)
        .Replacement.Text = Chr(-23583 + i)
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Next i
    Selection.Find.Execute Replace:=wdReplaceAll
        
    For i = 0 To 25
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = Chr(65 + i)
        .Replacement.Text = Chr(-23615 + i)
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Next i
    
    Selection.HomeKey

End Sub

--------------------编程问答-------------------- 不错。
鉴定完毕!
补充:VB ,  控件
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,