Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-19-2018, 10:50 PM
NevilleT NevilleT is offline Test for a blank line Windows 7 64bit Test for a blank line Office 2003
Novice
Test for a blank line
 
Join Date: Mar 2015
Posts: 29
NevilleT is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 06-19-2018, 11:29 PM
gmayor's Avatar
gmayor gmayor is offline Test for a blank line Windows 10 Test for a blank line Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,103
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 06-19-2018, 11:50 PM
NevilleT NevilleT is offline Test for a blank line Windows 7 64bit Test for a blank line Office 2003
Novice
Test for a blank line
 
Join Date: Mar 2015
Posts: 29
NevilleT is on a distinguished road
Default

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.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Test for a blank line 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
Test for a blank line 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
Test for a blank line Blank Line Supression Nibbles Mail Merge 4 11-21-2012 02:32 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:41 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft