Hello again,
I apologize for the delay, I have been quite busy with other projects but finally found the time today to dedicate some time to this. I was working through it and doing some editing of my document and decided to take the time to stop and test it using the macros we had discussed, and ran into a few issues.
In order to give you a better idea of what I am doing, I have provided a rough copy of the document I have created and will be using (I removed some information and shortened it, it is typically 16 pages but I removed a lot to keep the example a little shorter). The first 3 pages are the cover section, and everything beyond page 4 would be the scope section. Only Division 1 is formatted properly in the scope section, but the rest of the divisions will look very similar to Division 1, just to give examples.
The idea is that each section will be its own table, so that I can use the code suggested by macropod in his sample he provided me with last time I needed help. This will allow the ability to both select a header checkbox to remove the entire section, or the ability to select specific check boxes in a section to remove those rows.
The code is as follows:
Code:
Sub DeleteCheckedContent()
Application.ScreenUpdating = False
Dim Tbl As Table, r As Long
For Each Tbl In ActiveDocument.Tables
With Tbl
If .Cell(1, 1).Range.ContentControls(1).Checked = True Then
For r = .Rows.Count To 3 Step -1
.Rows(r).Delete
Next
.Cell(2, 2).Range.Text = "Not applicable"
Else
For r = .Rows.Count To 2 Step -1
If .Cell(r, 1).Range.ContentControls(1).Checked = True Then .Rows(r).Delete
Next
End If
.Columns(1).Delete
End With
Next
Application.ScreenUpdating = True
End Sub
However, when I run that code in the attached document (I selected the checkboxes for the Summary of Work header, Unit Prices Header, and miscellaneous options in the Exclusions sections as a test), I get "Run-time error '5941': The requested member of the collection does not exist", and I am not sure what is causing it. I attempted to read back through the code and work through to document to determine the issue, but cannot figure out what exactly would be causing this error.
The other issue I noticed, and this is mostly my own fault, is that in tables with more than 2 columns (I recently had to create these due to specific formatting requests), the "Not applicable" addition goes into row 2, column 2, as specified in the code, but it is not centered or formatted properly since there are 3 or 4 rows (as seen below Unit Prices in the example). Is there any way to format this so that it merges the cells, or to simply create a new row with only 1 column so "Not Applicable" will display properly?
Once again, I apologize for what are probably dumb questions, but I appreciate you giving me the opportunity to learn and understand Word and macros more as you have helped me through this.
Thank you so much,
Shane