True Title Case for First Row of All Tables
I have a macro I found online that sets “true title case” for any text that’s selected (it places articles such as “a”, “an”, “the”, etc. in lower case unless they are at the beginning of the text as an alternative to Word’s case-changing function). It works very well when the text whose case is to be changed to title case is selected.
I am trying to get this to work for the first row text of all tables in a document, but not having success. The “FormatAllTables” macro is my attempt to achieve this, and it selects the first row of each table, then calls “TrueTitleCase” to handle the case work. I know it’s not good practice to use the selection method, but I’ve other approaches, such as trying to capture just the text instead of the whole row, and been unable to make it work. My early attempts did change the case of the first row of each table, but whenever the first word was one that is in the TrueTitleCase array, it was changed to lower case. I believe this is because the “.MoveEnd Unit:=wdCharacter, Count:=-Len(sText) + 1” line works only when the text is manually selected (so that only the text is highlighted instead of the whole row), but I can’t get the macro to select only the text as it loops through the first row of each table, and I haven’t come up with an alternative to selecting the row that works.
The current version shown here handles the first row properly, but also changes the case of the other rows in the table for words that appear in the array. In other words, the case-changing code is not restricted to only the first row.
Any ideas on how to make this work?
Code is attached.
|