Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-05-2017, 04:34 PM
Jfedora Jfedora is offline Removing KeepWithNext Formatting from Nested Tables? Windows 7 32bit Removing KeepWithNext Formatting from Nested Tables? Office 2010 32bit
Novice
Removing KeepWithNext Formatting from Nested Tables?
 
Join Date: Jun 2017
Posts: 4
Jfedora is on a distinguished road
Default Removing KeepWithNext Formatting from Nested Tables?

Hello,
I have a document that is one big table with three Columns that has various other Tables within the middle Column. I am trying to remove Keep with next from the row in the larger all encompassing table that is above the smaller table, so that the tables don't split across pages. I used a macro that I found on here for a similar endeavor, just not in a giant table.

Code:
Public Sub KeepRowsTogether()
'Keeps Tables on one page
Dim oTbl As Table, oCel As Cell
'Iterate through all tables in document
For Each oTbl In ActiveDocument.Tables	
    oTbl.Range.Paragraphs.KeepWithNext = True
	With oTbl
	'If there are no merged vertical cells, turn off KeepWithNext on last row
    If .Uniform = True Then
      For Each oCel In .Rows.Last.Range.Cells
        oCel.Range.Paragraphs.Last.KeepWithNext = False
      Next oCel
    Else
	'Find vertically merged cells and turn off KeepWithNext 
      Set oCel = .Range.Cells(.Range.Cells.Count)
      Do While oCel.ColumnIndex > 1
        oCel.Range.Paragraphs.Last.KeepWithNext = False
        Set oCel = oCel.Previous
      Loop
      oCel.Range.Paragraphs.Last.KeepWithNext = False
    End If
  End With
Next oTbl
End Sub
I'm already parsing through all the tables like so:


Code:
'Loops through all tables in large Table
For Each InnerTable In OutterTable.Tables
	InnerTable.PreferredWidthType = wdPreferredWidthPoints
	InnerTable.PreferredWidth = 400
I was wondering if anyone could help me with how to get this formatting changed. Thanks

Last edited by Jfedora; 06-06-2017 at 10:53 AM.
Reply With Quote
  #2  
Old 06-06-2017, 10:38 AM
Jfedora Jfedora is offline Removing KeepWithNext Formatting from Nested Tables? Windows 7 32bit Removing KeepWithNext Formatting from Nested Tables? Office 2010 32bit
Novice
Removing KeepWithNext Formatting from Nested Tables?
 
Join Date: Jun 2017
Posts: 4
Jfedora is on a distinguished road
Default

Ok, I'm trying a different method now. As opposed to iterating through the tables and trying to find the position in the larger table, I'm iterating through all the cells of the large table and checking if there is a table in it, then removing the formatting from the row above.

Code:
Set LargeTable = ActiveDocument.Tables(1)
For Y = 0 to LargeTable.Rows.Count
	For X = 0 to LargeTable.Columns.Count
		If LargeTable.Cells(Y,X).Tables.Count = 0 Then
			Next X
		Else
			LargeTable.Row(Y-1).ParagraphFormat.KeepWithNext = False
			Next X
Next Y
However this is giving me an error here:
Code:
If LargeTable.Cells(Y,X).Tables.Count = 0 Then
Saying Object member does not exist. I'm also fairly certain my check to see if there is a table is going to fail as well.
Reply With Quote
  #3  
Old 06-06-2017, 10:46 AM
Jfedora Jfedora is offline Removing KeepWithNext Formatting from Nested Tables? Windows 7 32bit Removing KeepWithNext Formatting from Nested Tables? Office 2010 32bit
Novice
Removing KeepWithNext Formatting from Nested Tables?
 
Join Date: Jun 2017
Posts: 4
Jfedora is on a distinguished road
Default

Right after posting I saw my mistake of using 'Cells' instead of 'Cell'. However now I get a 'Next without For' error on this:

Code:
For Y = 0 To LargeTable.Rows.Count
        For X = 0 To LargeTable.Columns.Count
                If LargeTable.Cell(Y, X).Tables.Count = 0 Then
                        Next X
                Else
                        LargeTable.Row(Y - 1).ParagraphFormat.KeepWithNext = False
                        Next X
                End If
Next Y
Specifically on This:
Code:
If LargeTable.Cell(Y, X).Tables.Count = 0 Then
                        Next X
Though I suspect that it will apply to all of my Next statements
Reply With Quote
  #4  
Old 06-06-2017, 11:49 AM
Jfedora Jfedora is offline Removing KeepWithNext Formatting from Nested Tables? Windows 7 32bit Removing KeepWithNext Formatting from Nested Tables? Office 2010 32bit
Novice
Removing KeepWithNext Formatting from Nested Tables?
 
Join Date: Jun 2017
Posts: 4
Jfedora is on a distinguished road
Default

I was able to get it to work with this. Unfortunately, My tables are still rolling over pages, but that's another problem.

Code:
For Y = 0 To LargeTable.Rows.Count
    X = 0
    Do While X < LargeTable.Columns.Count
        If LargeTable.Cell(Y, X).Tables.Count = 1 Then
            X = X + 1
            LargeTable.Rows(Y - 2).Select
            Selection.ParagraphFormat.KeepWithNext = False
            Exit Do
        End If
        X = X + 1
        Loop
Next Y
Reply With Quote
Reply

Tags
keep with next, table, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested tables. Count rows NevilleT Word VBA 9 05-10-2017 05:22 AM
Remove Styles in Word 2016 without removing formatting stm27 Word 5 11-16-2016 12:49 PM
Would like help removing "tables" for boxes from document Alex MacLean Word 3 02-22-2015 01:39 PM
Formatting all tables knightmetal Word 2 09-10-2012 10:53 PM
Nested vlookup with varable tables! Dave Jones Excel 0 08-30-2012 09:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:21 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