Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-03-2016, 03:48 PM
jeffreybrown jeffreybrown is offline Error adding row to table Windows Vista Error adding row to table Office 2007
Expert
Error adding row to table
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default Error adding row to table

This macro works fine until it hits a table where there are vertically merged cells in the table. I get an error 5991 "Cannot access individual rowsin this collection because the table has vertically merged cells"

Is is possible to add rows to those tables or do I just need to skip those tables and move on?



Code:
Sub Add_Rows_Table()
    Application.ScreenUpdating = False
    Dim Tbl As Table, Rng As Range
    For Each Tbl In ActiveDocument.Tables
        Tbl.Select
        Tbl.Rows.Add BeforeRow:=Selection.Rows(1)
    Next Tbl
    Application.ScreenUpdating = True
End Sub
Reply With Quote
  #2  
Old 05-03-2016, 04:09 PM
gmaxey gmaxey is offline Error adding row to table Windows 7 32bit Error adding row to table Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

You can add rows until the cows come home but you can't access a single row:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oTbl As Word.Table
  For Each oTbl In ActiveDocument.Tables
    oTbl.Rows.Add
  Next
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 05-03-2016, 04:23 PM
jeffreybrown jeffreybrown is offline Error adding row to table Windows Vista Error adding row to table Office 2007
Expert
Error adding row to table
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

I'm looking to add a row to the beginning of every table.

This macro just repeats adding a row to one table and that's it, plus it's at the bottom.

The table that is throwing up the error is a table where the first row of the table is merged vertically with cells below.

Let's say the table is 8X5

Cell D1 thru D3 is merged along with G1 thru G4
Reply With Quote
  #4  
Old 05-03-2016, 06:12 PM
macropod's Avatar
macropod macropod is offline Error adding row to table Windows 7 64bit Error adding row to table 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

You could use:
Code:
Sub Add_Rows_Table()
    Application.ScreenUpdating = False
    Dim Tbl As Table, Rng As Range
    For Each Tbl In ActiveDocument.Tables
        Tbl.Cell(1, 1).Range.Select
        Selection.InsertRowsAbove 1
    Next Tbl
    Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 05-03-2016, 06:28 PM
gmaxey gmaxey is offline Error adding row to table Windows 7 32bit Error adding row to table Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Jeffery,

I know what my code does because I wrote it. It would be beneficial if you would clearly state what you want to do in "words" upfront.

You can insert a new row before the first row like this:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oTbl As Word.Table
  For Each oTbl In ActiveDocument.Tables
    oTbl.Range.Select
    Selection.Collapse wdCollapseStart
    Selection.InsertRowsAbove 1
  Next oTbl
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #6  
Old 05-03-2016, 06:29 PM
jeffreybrown jeffreybrown is offline Error adding row to table Windows Vista Error adding row to table Office 2007
Expert
Error adding row to table
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Thanks Paul...that does it...
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding comments to PPT slides causes error Render9 PowerPoint 0 02-09-2016 08:46 AM
Adding ContentControl to a table milena Word VBA 2 04-20-2015 01:04 AM
Error adding row to table Table property adding spacing Ulodesk Word Tables 4 01-12-2015 01:23 PM
Error adding row to table Adding Rows to a Table SuzeG Word VBA 8 01-02-2014 08:05 AM
Error adding row to table adding table to a particular place hklein Word VBA 2 07-25-2011 01:45 AM

Other Forums: Access Forums

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


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