WD: WordBasic Macros to Find the ANSI Value of Characters
ID: Q74894
|
The information in this article applies to:
-
Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
-
Microsoft Word for Windows 95, versions 7.0, 7.0a
-
Microsoft Word for the Macintosh, versions 6.0, 6.0.1, 6.0.1a
SUMMARY
To troubleshoot a problem or search for an extended character, you may
need to find the ANSI value of a string of text in Microsoft Word.
MORE INFORMATION
Below are two simple macros to find the ANSI value of a string of text. The
first is for one character selections and the second is for strings or
formatting characters.
The application note titled "WordBasic Macro Examples for Word for
Windows 2.0" includes a macro named ANSIChar. For additional information,
please see the following article in the Microsoft Knowledge Base:
Q100491 WD0523: Frequently Requested Macros Descriptions
WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN
RISK. Microsoft provides this macro code "as is" without warranty of any
kind, either express or implied, including but not limited to the implied
warranties of merchantability and/or fitness for a particular purpose.
Macro 1
Sub Main
A$=Selection$() '* A$ = highlighted text
Print Asc(A$) '* Print ANSI value of the first
'* character in A$ on the Status bar.
End Sub
This macro displays its result on the status bar.
Macro 2
You can use this macro for formatting characters or dissecting any
size text string. It displays both character and ANSI values in a
message box.
Sub Main
A$ = Selection$() '*A$=Highlighted text
While Len(A$) >=1 '* While the Length of A$ is
'* greater than 1
CharValue = ASC(A$) '* the ANSI value of 1st character
If Len(A$) >1 Then '* Reducing the length of A$
A$ = Mid$(A$, 2) '* A$ = A$ minus the 1st character
Else
A$="" '* A$ = nothing
End if
MsgBox Chr$(34) + Chr$(CharValue) + Chr$(34) + " ASC val = " +
Str$(CharValue) '* Display values in a message box
Wend '* end while loop
End Sub
To use these macros most efficiently, follow these steps:
- From the Tools menu in Word for Windows 2.0, choose Macro, type a
macro name, and choose the Edit button. From the Macro menu in Word
for Windows 1.x, choose Edit, type a macro name, and choose the OK
button.
- Type the macro.
- Choose File, Close, and save the macro when prompted.
- Select the text to run the macro on.
- Choose Tools, Macro. Highlight the macro name and choose Run.
Additional query words:
tshoot
Keywords : kbtshoot wordnt kbmacroexample kbfield winword macword word6 winword2 word7 word95 kbhowto macword6
Version : MACINTOSH:6.0,6.0.1,6.0.1a; WINDOWS:1.0,1.1,1.1a,2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a
Platform : MACINTOSH WINDOWS
Issue type :
|