Microsoft Office Forums Fix irregular shape of merged tables in MS Word 2007

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-29-2015, 04:22 AM
iyoossaev iyoossaev is offline Fix irregular shape of merged tables in MS Word 2007 Windows 7 64bit Fix irregular shape of merged tables in MS Word 2007 Office 2007
Novice
Fix irregular shape of merged tables in MS Word 2007
 
Join Date: Dec 2015
Posts: 6
iyoossaev is on a distinguished road
Default Fix irregular shape of merged tables in MS Word 2007

I have been looking for the answer to this for quite some time, but to no avail, so I hope someone here will be able to help me.



I have recently exported a document from FineReader 12 to word. The document is basically a 130-page-long table. The table has a regular shape: 5 columns, no merged cells.

However, when I merge individual tables (FineReader splits them by page) into one by deleting the lines between them, the table gets an irregular shape on each joint, like this.

Given the sheer number of tables I have, is there a way to reset their shape altogether? So far it seems I have to manually adjust each table's columns to fit the other ones.

I have tried resetting the table and column width, text wrapping etc.; I also selected the entire table and checked, then unchecked the "table header" tick for all.

Converting table to text and back doesn't work, because some cells have paragraph breaks, and that's to be dealt with later.
Reply With Quote
  #2  
Old 01-03-2016, 11:47 PM
macropod's Avatar
macropod macropod is online now Fix irregular shape of merged tables in MS Word 2007 Windows 7 64bit Fix irregular shape of merged tables in MS Word 2007 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,480
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

The problem is that your tables have differing layouts. The simplest solution would be to use a macro to format all of the tables with the same layout, then delete the intervening paragraph breaks. For example:
Code:
Sub FixTables()
Application.ScreenUpdating = False
Dim Tbl As Table
With ActiveDocument
  For Each Tbl In .Tables
    With Tbl
      With .Rows
        .LeftIndent = 0
        .WrapAroundText = False
        .Alignment = wdAlignRowCenter
      End With
      .TopPadding = 0
      .LeftPadding = 0
      .RightPadding = 0
      .BottomPadding = 0
      .AllowAutoFit = False
      .PreferredWidthType = wdPreferredWidthAuto
      .Columns(1).Width = CentimetersToPoints(1#)
      .Columns(2).Width = CentimetersToPoints(3.75)
      .Columns(3).Width = CentimetersToPoints(3.75)
      .Columns(4).Width = CentimetersToPoints(3.75)
      .Columns(5).Width = CentimetersToPoints(3.75)
  End With
  While .Tables.Count > 1
    .Tables(1).Range.Characters.Last.Next.Delete
  Wend
Next
End With
Application.ScreenUpdating = True
End Sub
For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 01-05-2016, 03:03 AM
iyoossaev iyoossaev is offline Fix irregular shape of merged tables in MS Word 2007 Windows 7 64bit Fix irregular shape of merged tables in MS Word 2007 Office 2007
Novice
Fix irregular shape of merged tables in MS Word 2007
 
Join Date: Dec 2015
Posts: 6
iyoossaev is on a distinguished road
Default

Thank you very much for responding.

I have just tried your macro and it gave me runtime error 5992, saying that I cannot access specific columns in the collection, because cells have different width. It did combine the tables, but the problem of varying column width persisted.

Would you be so kind as to suggest what might be wrong? Perhaps the macro should include formatting cell width to default?

Last edited by iyoossaev; 01-05-2016 at 04:26 AM. Reason: typo
Reply With Quote
  #4  
Old 01-05-2016, 03:54 AM
macropod's Avatar
macropod macropod is online now Fix irregular shape of merged tables in MS Word 2007 Windows 7 64bit Fix irregular shape of merged tables in MS Word 2007 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,480
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

The error suggests your document has one or more tables where the cell widths in a given column differ. That's only something I expected to occur if you had already merged some tables. That said, the following modifications should address the issue:
Code:
Sub FixTables()
Application.ScreenUpdating = False
Dim Tbl As Table, i As Long
With ActiveDocument
  For Each Tbl In .Tables
    With Tbl
      With .Rows
        .LeftIndent = 0
        .WrapAroundText = False
        .Alignment = wdAlignRowCenter
      End With
      .TopPadding = 0
      .LeftPadding = 0
      .RightPadding = 0
      .BottomPadding = 0
      .AllowAutoFit = False
      .PreferredWidthType = wdPreferredWidthAuto
      If .Uniform Then
        .Columns(1).Width = CentimetersToPoints(1#)
        .Columns(2).Width = CentimetersToPoints(3.75)
        .Columns(3).Width = CentimetersToPoints(3.75)
        .Columns(4).Width = CentimetersToPoints(3.75)
        .Columns(5).Width = CentimetersToPoints(3.75)
      Else
        For i = 1 To .Range.Cells.Count
          Select Case (i - 1 Mod 5) + 1
            Case 1: .Range.Cells(i).Width = CentimetersToPoints(1#)
            Case Else: .Range.Cells(i).Width = CentimetersToPoints(3.75)
          End Select
        Next
      End If
  End With
  While .Tables.Count > 1
    .Tables(1).Range.Characters.Last.Next.Delete
  Wend
Next
End With
Application.ScreenUpdating = True
End Sub
There is no such thing as a default cell width in Word.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #5  
Old 01-05-2016, 04:59 AM
iyoossaev iyoossaev is offline Fix irregular shape of merged tables in MS Word 2007 Windows 7 64bit Fix irregular shape of merged tables in MS Word 2007 Office 2007
Novice
Fix irregular shape of merged tables in MS Word 2007
 
Join Date: Dec 2015
Posts: 6
iyoossaev is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
The error suggests your document has one or more tables where the cell widths in a given column differ. That's only something I expected to occur if you had already merged some tables.
Weird, I paid attention not to merge any in a freshly-generated file.

Quote:
Originally Posted by macropod View Post
There is no such thing as a default cell width in Word.
Indeed, my wording could have been better — I meant that by default cell width is inherited after column width.

Quote:
Originally Posted by macropod View Post
That said, the following modifications should address the issue
And they did — you literally saved me dozens of hours of work. Thanks a bunch!

The only downside is that while it takes seconds to parse 2 pages worth of tables, it takes forever to parse 20 pages with numerous prompts in-between. But I guess that's hardware and Word itself.
Reply With Quote
  #6  
Old 01-05-2016, 05:03 AM
iyoossaev iyoossaev is offline Fix irregular shape of merged tables in MS Word 2007 Windows 7 64bit Fix irregular shape of merged tables in MS Word 2007 Office 2007
Novice
Fix irregular shape of merged tables in MS Word 2007
 
Join Date: Dec 2015
Posts: 6
iyoossaev is on a distinguished road
Default

Is there any way to suppress the prompts in the macro that ask if I should continue with irreversible changes?

Edit: I think I actually found the solution to that, leaving it for posteriority with similar problems.
It suffices to add
Code:
Application.Displayalerts = False
at the beginning, and
Code:
Application.Displayalerts = True
at the end to restore the prompts back.

Last edited by iyoossaev; 01-05-2016 at 05:23 AM. Reason: found the solution
Reply With Quote
  #7  
Old 01-05-2016, 02:36 PM
macropod's Avatar
macropod macropod is online now Fix irregular shape of merged tables in MS Word 2007 Windows 7 64bit Fix irregular shape of merged tables in MS Word 2007 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,480
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

OK, try this version:
Code:
Sub FixTables()
Application.ScreenUpdating = False
Dim Tbl As Table, i As Long
With ActiveDocument
  For Each Tbl In .Tables
    With Tbl
      With .Rows
        .LeftIndent = 0
        .WrapAroundText = False
        .Alignment = wdAlignRowCenter
      End With
      .TopPadding = 0
      .LeftPadding = 0
      .RightPadding = 0
      .BottomPadding = 0
      .AllowAutoFit = False
      .PreferredWidthType = wdPreferredWidthAuto
      .Columns.DistributeWidth
      .Columns(1).Width = CentimetersToPoints(1#)
      .Columns(2).Width = CentimetersToPoints(3.75)
      .Columns(3).Width = CentimetersToPoints(3.75)
      .Columns(4).Width = CentimetersToPoints(3.75)
      .Columns(5).Width = CentimetersToPoints(3.75)
  End With
  While .Tables.Count > 1
    .Tables(1).Range.Characters.Last.Next.Delete
  Wend
Next
End With
Application.ScreenUpdating = True
End Sub
What are the prompts? Without knowing what they are, I can't say whether there's a better approach than toggling Displayalerts.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #8  
Old 01-05-2016, 03:18 PM
iyoossaev iyoossaev is offline Fix irregular shape of merged tables in MS Word 2007 Windows 7 64bit Fix irregular shape of merged tables in MS Word 2007 Office 2007
Novice
Fix irregular shape of merged tables in MS Word 2007
 
Join Date: Dec 2015
Posts: 6
iyoossaev is on a distinguished road
Default

Thanks for getting back to me again.

The prompts it gives me are (roughly translating):
Program Word has encountered an error. After completing this operating it will be irreverisible. Do you want to continue?
When I click yes, it goes on for a bit before asking again; whenI press no, it gives me a series of identical prompts, but force-quitting this chain leaves the fille partially of fully "fixed" with respect to tables.

I tried your last solution, but I am getting runtime error 4605, saying that when cells spanning multiple rows are selected, the number of columns must be the same. I don't get that when I use the previous solution on the same file, but it is possible something is merged somewhere
Reply With Quote
  #9  
Old 01-05-2016, 04:05 PM
macropod's Avatar
macropod macropod is online now Fix irregular shape of merged tables in MS Word 2007 Windows 7 64bit Fix irregular shape of merged tables in MS Word 2007 Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,480
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

The prompts are merely telling you there'll be too many edits for Word to undo. In this case, toggling DisplayAlerts is probably the best way of handling it.

If there are cells spanning multiple rows, your table has merged cells, contrary to what you previously advised. In that case, you'll need to iterate through the cells of the tables concerned. That said, you may get a slight performance increase with:
Code:
Sub FixTables()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim Tbl As Table, i As Long
With ActiveDocument
  For Each Tbl In .Tables
    With Tbl
      With .Rows
        .LeftIndent = 0
        .WrapAroundText = False
        .Alignment = wdAlignRowCenter
      End With
      .TopPadding = 0
      .LeftPadding = 0
      .RightPadding = 0
      .BottomPadding = 0
      .AllowAutoFit = False
      .PreferredWidthType = wdPreferredWidthAuto
      On Error Resume Next
      .Columns.DistributeWidth
      On Error GoTo 0
      If .Uniform Then
        .Columns(1).Width = CentimetersToPoints(1#)
        .Columns(2).Width = CentimetersToPoints(3.75)
        .Columns(3).Width = CentimetersToPoints(3.75)
        .Columns(4).Width = CentimetersToPoints(3.75)
        .Columns(5).Width = CentimetersToPoints(3.75)
      Else
        For i = 1 To .Range.Cells.Count
          With .Range.Cells(i)
            If .ColumnIndex = 1 Then
              .Width = CentimetersToPoints(1#)
            Else
              .Width = CentimetersToPoints(3.75)
            End If
          End With
        Next
      End If
  End With
  While .Tables.Count > 1
    .Tables(1).Range.Characters.Last.Next.Delete
  Wend
Next
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #10  
Old 01-06-2016, 08:43 AM
iyoossaev iyoossaev is offline Fix irregular shape of merged tables in MS Word 2007 Windows 7 64bit Fix irregular shape of merged tables in MS Word 2007 Office 2007
Novice
Fix irregular shape of merged tables in MS Word 2007
 
Join Date: Dec 2015
Posts: 6
iyoossaev is on a distinguished road
Default

Thanks for yet another contribution. It is difficult to say by eye if the overall perfomance is better not., but I trust it is. It's by far the best solution I've come across and it does work even if I miss merged cells, so I will proceed to use this. Cheers!
Reply With Quote
Reply

Tags
format data in cell, merge tables

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining 2 tables into 1 and use Table2's column widths (hoping for workaround dealing merged cells CodingGuruInTraining Word VBA 24 10-07-2015 07:48 PM
Fix irregular shape of merged tables in MS Word 2007 How to make gridlines in cells of tables in MS Word 2007 pgrewal Drawing and Graphics 1 07-18-2014 11:12 PM
Irregular results using Table of Figures justphilip2003 Word 2 01-23-2014 02:26 PM
Fix irregular shape of merged tables in MS Word 2007 Identifying Irregular Characters d4okeefe Word VBA 2 05-09-2013 03:14 PM
Word 2007 TOC Updates to Include Tables and Styles rphox2003 Word 6 10-21-2012 06:41 AM


All times are GMT -7. The time now is 05:05 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Search Engine Optimisation provided by DragonByte SEO v2.0.37 (Lite) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft