#1
|
|||
|
|||
Variable filler rows in an incomplete table
Good day,
I'm creating RTF templates for reports whose layout is very specific. If there is not enough data to fill a table such that it expands to the bottom of the page, I must instead insert rows of shading or diagonal lines to prevent anyone adding anything 'unofficial' into the blank rows. For example in the attached JPG there are two data rows, but that leaves 12 empty rows that must be rendered 'out of bounds' by some form of shading. I manually added the rows of periods here, but I need to know if this can be automated such that it will fill up redundant rows to the end of the page. Any ideas gratefully received. TIA. |
#2
|
||||
|
||||
Where does the data come from that fills the two used rows, or how is the number of used rows determined? If the data is being added by a macro process, as seems to be the case, then it would probably be better to begin with all the cells filled with characters and overwrite them as required with the process.
Ensuring that the random number of cells are not themselves overwritten by someone is a different issue and questions the reason for using an editable format in the first place. If you don't want users to edit the table manually then take that away from them by converting to (say) pdf or make the document read only.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Thanks for replying, Graham.
The RTF file is a template for reports via Oracle Business Intelligence Publisher. One associates the template with an XML file, and then by putting placeholders in the RTF document and linking them to various elements in the XML document. BI then does a sort of mailmerge and creates a report by inserting the XML data where required. As for preventing anyone overwriting a blank space, we are talking about a printed document, not the soft copy. The work is for agricultural export quarantine documents, the format of which is agreed and signed in blood by the exporting and importing governments. The worry is that, say, meat or grain that has not been inspected might be photocopied/whatever onto the list of items that have been cleared. I know it's pretty anal, but we're talking government bureaucrats here. Mine is not to reason why... As for pre-filling the cells with 'shading', I tried that but as it fills rows with data it merely pushes the shaded rows down and onto the next page. Is there a way I could pre-fill rows which can then be overwritten by data as needed, rather than expanding the table downwards? |
#4
|
||||
|
||||
Without access to your process to change the part of the code that writes to the cell to replace the cell content rather than add to it, a pre-filled table is not going to be easy to achieve. The best I can manage for the moment is to fill the empty cells using a Word macro.
Code:
Sub FillTable() Dim oTable As Table Dim oCell As Cell Dim oRng As Range Dim i As Long If Not ActiveDocument.Tables.Count = 1 Then MsgBox "Invalid Document" GoTo lbl_Exit End If Set oTable = ActiveDocument.Tables(1) If Not oTable.Rows.Count = 13 Then 'the number of rows in the table MsgBox "Invalid Document - Row count = " & oTable.Rows.Count GoTo lbl_Exit End If For i = oTable.Range.Cells.Count To 1 Step -1 Set oCell = oTable.Range.Cells(i) If Len(oCell.Range) = 2 Then Set oRng = oCell.Range oRng.End = oRng.End - 1 oRng.Text = "....................." 'to fill the length of the cell End If Next i lbl_Exit: Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
Thanks again Graham,
I will try it out now. I was hoping to avoid VBA, as we have several hundred of these templates and the guys who will be building them are business, not tech-heads. However from what you say, and I agree, there is no other way. The poor guys will just have to become techies! |
#6
|
||||
|
||||
It would help if you offered the users an add-in template containing the code - see attached.
This code is slower than the previous code, but it will put the correct number of periods in the cells no matter the size of the cell.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#7
|
|||
|
|||
Cheers Graham, this is enough for me to work on.
I will hassle you again if I have any problems! Thanks for your help and time. Sholto |
Tags |
shading, table, variable |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Would like a macro to copy a cell down a variable number of rows | Rod_Bowyer | Excel Programming | 6 | 03-25-2016 08:18 PM |
Mail merge at large table with variable number of rows | blar | Mail Merge | 1 | 10-19-2015 03:04 PM |
Incomplete Table of Contents (Mac Office 2011) | lead48 | Word | 2 | 05-31-2015 06:28 AM |
Creating a table for a variable number of rows | OllieOnline | Mail Merge | 1 | 03-27-2013 02:48 PM |
Using macro to add variable number of rows to a protected word table | Julia | Word Tables | 1 | 01-09-2013 06:04 AM |