WD: WordBasic Macros to Find the ANSI Value of Characters

Last reviewed: February 24, 1998
Article 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
  • 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:

   ARTICLE-ID: Q100491
   TITLE     : 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:

  1. 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.

  2. Type the macro.

  3. Choose File, Close, and save the macro when prompted.

  4. Select the text to run the macro on.

  5. Choose Tools, Macro. Highlight the macro name and choose Run.


Additional query words: tshoot
Keywords : kbfield kbhowto kbmacroexample macword winword winword2 word6 word7 word95 wordnt macword6 kbtshoot
Version : WINDOWS:2.0,2.0a,2.0a-CD,2.0c,6.0,6.0a,6.0c,7.0,7.0a; MACINTOSH:6.0, 6.0.1
Platform : MACINTOSH WINDOWS
Issue type : kbappnote


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 24, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.