VBA Gerus,

Is there a function in VBA to derermine if a character is an ASCII
character (A - Z or a - z)? I need something like this: msgbox
IsASCII(aWord) returning a one or zero.

Thanks.

Charlie from Texas

Re: ISASCII function by Jay

Jay
Mon Feb 25 18:35:35 PST 2008

On Mon, 25 Feb 2008 14:28:11 -0600, Charlie Mac <> wrote:

>VBA Gerus,
>
>Is there a function in VBA to derermine if a character is an ASCII
>character (A - Z or a - z)? I need something like this: msgbox
>IsASCII(aWord) returning a one or zero.
>
>Thanks.
>
>Charlie from Texas

To correct a misconception, ASCII (now called ANSI) characters include much more
than A-Z and a-z -- the digits, punctuation, and all other characters in the
range from 0 to 255 are 'ASCII characters'. So I wrote the function name as
IsAlpha instead.

Function IsAlpha(s As String) As Boolean
Dim retVal As Boolean
retVal = False

If Len(s) > 0 Then
If Left$(s, 1) Like "[A-Za-z]" Then
retVal = True
End If
End If

IsAlpha = retVal
End Function

Sub test()
Dim myText As String
Dim myChar As String
Dim msg As String
Dim i As Long

myText = Selection.Text
For i = 1 To Len(myText)
myChar = Mid$(myText, i, 1)
msg = "'" & myChar & "' is "
If Not IsAlpha(myChar) Then
msg = msg & "NOT "
End If
msg = msg & "in [A-Za-z]"
MsgBox msg
Next
End Sub

As written, this function checks only one character, the first one in the string
passed in as the parameter. If you meant to check a whole word or an entire
string, that would need some slightly different logic.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.

Re: ISASCII function by Charlie

Charlie
Wed Feb 27 06:49:13 PST 2008

Jay,

Thank you for your reply. I did not know that the "Like" function
existed. Your code solved my problem.

Take care,

Charlie from Texas

On Mon, 25 Feb 2008 21:35:35 -0500, Jay Freedman
<jay.freedman@verizon.net> wrote:

>On Mon, 25 Feb 2008 14:28:11 -0600, Charlie Mac <> wrote:
>
>>VBA Gerus,
>>
>>Is there a function in VBA to derermine if a character is an ASCII
>>character (A - Z or a - z)? I need something like this: msgbox
>>IsASCII(aWord) returning a one or zero.
>>
>>Thanks.
>>
>>Charlie from Texas
>
>To correct a misconception, ASCII (now called ANSI) characters include much more
>than A-Z and a-z -- the digits, punctuation, and all other characters in the
>range from 0 to 255 are 'ASCII characters'. So I wrote the function name as
>IsAlpha instead.
>
>Function IsAlpha(s As String) As Boolean
> Dim retVal As Boolean
> retVal = False
>
> If Len(s) > 0 Then
> If Left$(s, 1) Like "[A-Za-z]" Then
> retVal = True
> End If
> End If
>
> IsAlpha = retVal
>End Function
>
>Sub test()
> Dim myText As String
> Dim myChar As String
> Dim msg As String
> Dim i As Long
>
> myText = Selection.Text
> For i = 1 To Len(myText)
> myChar = Mid$(myText, i, 1)
> msg = "'" & myChar & "' is "
> If Not IsAlpha(myChar) Then
> msg = msg & "NOT "
> End If
> msg = msg & "in [A-Za-z]"
> MsgBox msg
> Next
>End Sub
>
>As written, this function checks only one character, the first one in the string
>passed in as the parameter. If you meant to check a whole word or an entire
>string, that would need some slightly different logic.