The information in this article applies to:
SYMPTOMSWhen you run a Visual Basic for Applications macro to select a table cell and then test the contents of the cell or check whether the cell is empty, it may return a false or invalid result. CAUSEThis behavior is by design of Microsoft Word. In Microsoft Word for Windows, there are markers in every cell of the table that store formatting attributes. When you select a cell in a table manually by double-clicking it or programmatically with Select method, the cell marker is included in the selection. WORKAROUND
When you write macros to test the content of a cell in Word, you must
remove or account for two additional characters at the right side or end of
the selection. These characters represent the cell marker.
Method One--Check for a Character other Than Cell MarkerThis macro inserts a space at the end of the cell, and then moves the insertion point to the beginning of the cell. If MyVar returns a space, the cell is empty. This macro does not work with leading spaces in the text.
Method Two--Check All Cells in Table Suppress Leading SpacesThis macro checks the number of characters in a table cell, using the Len function to count the number of characters and LTrim function to suppress leading spaces in the selected content.To compensate for the cell marker, subtract 2 from the result of the LTrim and Len function. All of these features are combined together to apply to the content of the selection.
MORE INFORMATIONIn Word, when you select a blank table cell and examine the content, the values assigned to the code internally are different from the information displayed in a message box: A character count on the cell content returns the value one, while the Len function returns the value two. The text value of the selection displays a single vertical bar (|) on screen, and a double vertical bar (||) internally. Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/refguide/For more information about Len or Trim function, from the Visual Basic Editor, click Contents And Index on the Help menu, click the Index tab in Word Help, type the following text len or trimand then double-click the selected text to go to the "Len Function" topic. If you are unable to find the information you need, ask the Office Assistant. REFERENCESFor additional information, please see the following article in the Microsoft Knowledge Base: Q173707 OFF97: How to Run Sample Code from Knowledge Base Articles Additional query words: wordcon Table wd97 VBA Text blank
Keywords : kbdta KbVBA |
Last Reviewed: October 15, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |