#1
|
|||
|
|||
Test for a blank line
I am trying to come up with some code to test a situation.
I have a table which may, or may not have some text in a particular cell. I want to put another table within the cell. The new table would happen after the point where the user had placed the cursor. (Basically a box within a box). The table would be on the next line after the text. Alternatively, if there was no text, it would be at the top of the cell. There are two situations I want to test for. 1. If the selection is at the end of the text, I want to check if there is a blank line below the selection and if not add a line. - Selection.InsertAfter Chr(11) 2. If the selection is on a blank line, I will add the inner table on that line. The creation of the inner table works fine. Just having trouble getting to the right place to insert the table. |
#2
|
||||
|
||||
If you insert a table it will always be on a new 'line'. If you want that table at the end of the cell whether or not it contains text:
Set a range to the cell Omit the cell end character from the range. Delete the last empty 'line' Collapse the range Insert the table e.g. Code:
Dim oCell As Range Set oCell = Selection.Cells(1).Range oCell.End = oCell.End - 1 If oCell.Characters.Last = Chr(11) Or _ oCell.Characters.Last = Chr(13) Then oCell.Characters.Last.Delete End If oCell.Collapse 0 oCell.Tables.Add oCell, 1, 1
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Thanks Graham. So simple. I have spent hours on this and you solved it in about 10 minutes from when I posted the question. Very much appreciate your help.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Line Numbering & Blank Lines | Ephasa | Word | 9 | 04-30-2020 02:09 PM |
How do I select all blank line paragraphs in a doc? | eabeer | Word | 4 | 03-08-2018 12:19 AM |
Select and Delete 2 lines after each blank line | Ziad El Hachem | Word VBA | 4 | 03-21-2017 06:55 PM |
How to add a blank line within an exporting sub? | Geza59 | Excel Programming | 2 | 02-14-2013 12:23 AM |
Blank Line Supression | Nibbles | Mail Merge | 4 | 11-21-2012 02:32 AM |