Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-19-2013, 11:17 AM
SuzeG SuzeG is offline Adding Rows to a Table Windows 7 64bit Adding Rows to a Table Office 2010 64bit
Novice
Adding Rows to a Table
 
Join Date: Dec 2013
Location: Va Beach
Posts: 21
SuzeG is on a distinguished road
Default Adding Rows to a Table

Hello,
I have code to add 3 content control rows to the end of a table. That code works fine. It is the code to select the table to which the rows are to added that is my problem.
I have several tables in my document and I want the code to pertain to only the 7th table. I tried ActiveDocument.Tables(7) but I get the error "method or data member not found" at the first .Cell(1) line

Also, I am not sure if I have to indicate Tables(7) in the code.

Any help is very much appreciated. Thank you.

Code:
 
 Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
Dim p_oTargetRow As Word.Row
With ActiveDocument.Tables(7)
 ' With Selection.Range
 If .Information(wdWithInTable) Then
' If ContentControl.Range.InRange(.Range) Then
    If .Cells(1).RowIndex = .Tables(1).Range.Cells _
                            (.Tables(1).Range.Cells.Count).RowIndex Then
      If .Cells(1).ColumnIndex = .Tables(1).Range.Cells _
                                 (.Tables(1).Range.Cells.Count).ColumnIndex Then
        If MsgBox("This is the last row/last cell." _
                & " Do  you want to ADD new Performance Goal ROWS?", _
                  vbQuestion + vbYesNo, "New Row") = vbYes Then
          InsertRowWithContent
        End If
        Set p_oTargetRow = Selection.Rows(1)
      End If
    End If
  End If
' End With
End With
End Sub

Reply With Quote
  #2  
Old 12-19-2013, 04:11 PM
fumei fumei is offline Adding Rows to a Table Windows 7 64bit Adding Rows to a Table Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

try changing
.Cells(1).

to
.Range.Cells(1).
Reply With Quote
  #3  
Old 12-23-2013, 12:51 PM
SuzeG SuzeG is offline Adding Rows to a Table Windows 7 64bit Adding Rows to a Table Office 2010 64bit
Novice
Adding Rows to a Table
 
Join Date: Dec 2013
Location: Va Beach
Posts: 21
SuzeG is on a distinguished road
Default

That did not work.
I found this code online and adjusted it to copy three rows with contentcontrols to 3 new rows. However I cannot add this code to my document that contains many tables. This would be the 7th Table.
As a novice I am unclear how to specify that this code applies only to Table 7.

Code:
 
 Private Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
Dim p_oTargetRow As Word.Row
With Selection.Range
  If .Information(wdWithInTable) Then
    If .Cells(1).RowIndex = .Tables(1).Range.Cells _
                            (.Tables(1).Range.Cells.Count).RowIndex Then
      If .Cells(1).ColumnIndex = .Tables(1).Range.Cells _
                                 (.Tables(1).Range.Cells.Count).ColumnIndex Then
        If MsgBox("This is the last row/last cell." _
                & " Do  you want to ADD a new Performance Goal ROW?", _
                  vbQuestion + vbYesNo, "New Row") = vbYes Then
          InsertRowWithContent
        End If
        Set p_oTargetRow = Selection.Rows(1)
      End If
    End If
  End If
End With
End Sub
Thank you for your help.
Reply With Quote
  #4  
Old 12-23-2013, 06:00 PM
fumei fumei is offline Adding Rows to a Table Windows 7 64bit Adding Rows to a Table Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

Quote:
As a novice I am unclear how to specify that this code applies only to Table 7.

I do not understand. You test to see if the Selection is in a table, then you action THAT table. Not table(7) , although of course it could be, the one the selection is in. Are you saying that if the Selection is in table(4), or not in a table at all, you want to action table(7)?
Reply With Quote
  #5  
Old 12-26-2013, 08:07 AM
SuzeG SuzeG is offline Adding Rows to a Table Windows 7 64bit Adding Rows to a Table Office 2010 64bit
Novice
Adding Rows to a Table
 
Join Date: Dec 2013
Location: Va Beach
Posts: 21
SuzeG is on a distinguished road
Default

I have several tables in the same document. The code adds rows to a table by testing if the selection is in the last cell of the last column. I only want the coed to apply to table(7). For example, when I am in table six in the last cell the code runs.
Hope that makes more sense.
Reply With Quote
  #6  
Old 12-26-2013, 07:08 PM
fumei fumei is offline Adding Rows to a Table Windows 7 64bit Adding Rows to a Table Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

Just to confirm.

No matter WHAT table the selection is in, you ONLY want table(7) to be have action. In that case, change table(1) to table(7) IN THE PROCEDURE InsertRowWithContent.

Which, BTW, you have not posted.
Reply With Quote
  #7  
Old 12-27-2013, 10:30 AM
SuzeG SuzeG is offline Adding Rows to a Table Windows 7 64bit Adding Rows to a Table Office 2010 64bit
Novice
Adding Rows to a Table
 
Join Date: Dec 2013
Location: Va Beach
Posts: 21
SuzeG is on a distinguished road
Default

Sorry -
I am not sure about the etiquette of when I should post the code. I try to figure it out first on my own with your comments but I am at a loss.
I have uploaded the document.
Yes, I would like the procedure to work only on Table(7)
Thanks for your continued help.
Attached Files
File Type: zip NEXCOMFORM.zip (156.0 KB, 9 views)
Reply With Quote
  #8  
Old 12-27-2013, 02:06 PM
fumei fumei is offline Adding Rows to a Table Windows 7 64bit Adding Rows to a Table Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

I am a bit pressed for time so hopefully someone like macropod can speed up helping you. The problem is that your code for InsertRowWithContent (and InsertColumnWithContent) uses Selection. And now you are saying that you do NOT want to use Selection. Therefore things like:

Set oRows = Selection.Rows(1)

are wrong.

It all has to be changed to only use table(7) rows and columns.
Reply With Quote
  #9  
Old 01-02-2014, 08:05 AM
SuzeG SuzeG is offline Adding Rows to a Table Windows 7 64bit Adding Rows to a Table Office 2010 64bit
Novice
Adding Rows to a Table
 
Join Date: Dec 2013
Location: Va Beach
Posts: 21
SuzeG is on a distinguished road
Default

OK thanks for your input - Happy New Year!
Reply With Quote
Reply

Tags
content controls, rows



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Rows to a Table Grouping table rows to prevent individual rows from breaking across pages dennist77 Word 1 10-29-2013 11:39 PM
Adding Rows to a Table Adding rows and copying formulas ejtoll Word Tables 1 12-05-2012 05:09 PM
Adding columns in specific rows only mhays Excel 5 01-17-2012 09:13 AM
Adding Rows to a Table Odd behaviour of table - keep rows together Stephan Lindner Word Tables 1 09-10-2011 05:31 AM
Adding Rows to a Table adding rows to word table hklein Word VBA 4 07-18-2011 12:21 AM

Other Forums: Access Forums

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