Vba 检测所选内容是否为字母

Vba 检测所选内容是否为字母,vba,ms-word,word-2007,word-2003,Vba,Ms Word,Word 2007,Word 2003,我的文档中有很多空格和段落标记 我要做的是检测字符选择。find是否是从A到Z的任何字母 Dim EE As String Selection.Find.ClearFormatting With Selection.Find .Text = "^?" .Forward = True .Wrap = wdFindStop End With Selection.Find.Execute EE = Selection.Text If isletter = True Th

我的文档中有很多空格和段落标记

我要做的是检测字符
选择。find
是否是从A到Z的任何字母

Dim EE As String

Selection.Find.ClearFormatting
With Selection.Find
    .Text = "^?"
    .Forward = True
    .Wrap = wdFindStop
End With

Selection.Find.Execute

EE = Selection.Text

If isletter = True Then
    MsgBox ("Letter found")
Else
    MsgBox ("No letter found")
End If

如果要获取所选内容的第一个字符,还可以使用
Left(selection,1)
。如果要查找第一个字母,可以使用:

With Selection.Find
    .MatchWildcards = true
    .Text = "[a-zA-Z]"  '[A-Z] if you only want upper case
    .Forward = True
    .Wrap = wdFindStop
End With
如果想知道字符串(长度为1)是否为字母,可以使用
Like
进行模式匹配:

If EE Like "[A-Z]" Then   '"[a-zA-Z]" for upper and lower case
或者检查其unicode值

If AscW(EE)>=AscW("A") and AscW(EE)<=AscW("Z") Then  'for upper case letters

如果AscW(EE)>=AscW(“A”)和AscW(EE)如果要获取所选内容的第一个字符,也可以使用
Left(selection,1)
。如果要查找第一个字母,可以使用:

With Selection.Find
    .MatchWildcards = true
    .Text = "[a-zA-Z]"  '[A-Z] if you only want upper case
    .Forward = True
    .Wrap = wdFindStop
End With
如果想知道字符串(长度为1)是否为字母,可以使用
Like
进行模式匹配:

If EE Like "[A-Z]" Then   '"[a-zA-Z]" for upper and lower case
或者检查其unicode值

If AscW(EE)>=AscW("A") and AscW(EE)<=AscW("Z") Then  'for upper case letters

如果AscW(EE)>=AscW(“A”)和AscW(EE)对段落标记做了一些研究,发现
Chr(13)
可以检测
^p
(段落标记)

以下代码可以检测
段落标记
字母

Sub FindanyLetter()
Dim EE As String

        Selection.Find.ClearFormatting
        With Selection.Find
            .Text = "^?"
            .Forward = False
            .Wrap = wdFindStop
        End With
        Selection.Find.Execute

        EE = Selection.Text

        If EE = Chr(13) Or EE = " " Then

        MsgBox "Paraghraph mark or space"
        Else
        MsgBox "Letter"

        End If

    End Sub

对段落标记做了一些研究,发现
Chr(13)
可以检测
^p
(段落标记)

以下代码可以检测
段落标记
字母

Sub FindanyLetter()
Dim EE As String

        Selection.Find.ClearFormatting
        With Selection.Find
            .Text = "^?"
            .Forward = False
            .Wrap = wdFindStop
        End With
        Selection.Find.Execute

        EE = Selection.Text

        If EE = Chr(13) Or EE = " " Then

        MsgBox "Paraghraph mark or space"
        Else
        MsgBox "Letter"

        End If

    End Sub

是的,谢谢你的评论。这就是我没有尝试每一个角色所得到的…这是真的,谢谢你的评论。这就是我没有尝试每个角色所得到的。。。