Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 09-22-2015, 10:01 PM
macropod's Avatar
macropod macropod is offline Combining 2 tables into 1 and use Table2's column widths (hoping for workaround dealing merged cells Windows 7 64bit Combining 2 tables into 1 and use Table2's column widths (hoping for workaround dealing merged cells Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try the following macro for creating the new tables. They'll appear after the existing ones.
Code:
Sub Demo()
Dim wdDoc As Document, Tbl As Table, Rng As Range, i As Long, j As Long, k As Long
Application.ScreenUpdating = False
Set wdDoc = ActiveDocument
With wdDoc
  For i = .Tables.Count To 1 Step -1
    With .Tables(i).Range
      j = (.Cells(.Cells.Count).RowIndex - 1) / 2
      .Paragraphs.Last.Next.Range.InsertBefore vbCr & vbCr & vbCr & vbCr
      Set Rng = .Paragraphs.Last.Next.Next.Range
      Rng.Collapse wdCollapseStart
      Set Tbl = wdDoc.Tables.Add(Range:=Rng, NumRows:=2, NumColumns:=4, AutoFitBehavior:=False)
      With Tbl
        .Borders.Enable = True
        .Rows.HeightRule = wdRowHeightExactly
        .Rows(1).Height = InchesToPoints(0.25)
        .Rows(2).Height = InchesToPoints(0.5)
        .Cell(2, 1).VerticalAlignment = wdCellAlignVerticalCenter
        .Columns.PreferredWidthType = wdPreferredWidthPoints
        .Rows(1).Shading.BackgroundPatternColorIndex = wdTurquoise
        .Columns(1).Shading.BackgroundPatternColorIndex = wdTurquoise
        .Columns(1).Width = InchesToPoints(0.45)
        .Columns(2).Width = InchesToPoints(1.5)
        .Columns(3).Width = InchesToPoints(2.38)
        .Columns(4).Width = InchesToPoints(2.33)
        Set Rng = .Range
        With Rng
          .SetRange Start:=.Cells(6).Range.Start, End:=.Cells(8).Range.End
          .Cells.Split NumRows:=2, NumColumns:=1, MergeBeforeSplit:=False
          .Rows.HeightRule = wdRowHeightExactly
          .Cells.Height = InchesToPoints(0.25)
          .SetRange Start:=Tbl.Range.Cells(9).Range.Start, End:=Tbl.Range.End
          .Cells.Merge
          .SetRange Start:=Tbl.Range.Cells(5).Range.Start, End:=Tbl.Range.End
          .Copy
        End With
        For k = 2 To j
          With .Range.Paragraphs.Last.Next.Range
            .InsertBefore vbCr
            .Paste
          End With
        Next
      End With
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 

Tags
column width, combine, tables



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 Table will not allow sorting because "cells are merged". I can't find the merged cells. wendyloooo Word Tables 1 05-26-2015 01:19 PM
Splitting one column into two with two different widths officeboy09 Excel 6 12-15-2013 09:48 PM
Pasting tables from Excel 2010 into Word 2010 - How to fix column widths? GracieB Word 7 10-02-2013 06:24 AM
Adjusting column widths norwood Word VBA 0 09-24-2013 06:53 AM
Combining 2 tables into 1 and use Table2's column widths (hoping for workaround dealing merged cells VBA code to fix column widths molesy Excel 3 09-16-2013 12:51 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:59 AM.


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