Word table cell marking routine needed

B

Bill Planey

Hello,

I have a thorny problem that I am hoping for a creative solution to - I have
scripts that convert Word tables to tab-separated text, but because some
cells are (intentionally) left empty in the source document, I need a way to
mark them before they are collapsed so that in their collapsed state there
are not two consecutive tabs left behind, rather, a tab followed by a
placeholder string of my own devising, followed by the second tab. My script
consolidates consecutive tabs into a single tab later (because the vast
majority of consecutive tabs in such documents are truly unnecessary). The
only way to properly re-constitute the table that has an intentionally empty
cell in a number column is to mark the cell beforehand with a placeholder
string.

Sometimes, a cell directly above or below such cells will have a value in
it, so there is the possibility to script something that takes that into
account. But this is not always the case. I suppose a more reliable
scenario would be to check if ANY other cells in the same column have values
in them, which would validate leaving a placeholder in that particular empty
cell.

But what if the column has rows running through it that contain merged
cells? What if the cell is part of a row that is completely empty all the
way across - just there to add vertical space? How can you truly automate
this if there are so many potential forms of interference with a clear-cut
approach?

I don't know if this newsgroup allows attachments, so I have not included
one. But if requested, I'll post again with a sample table that has a
yellow cell that illustrates my dilemma.

BTW, my solution will be VBA code executed via AppleScript.

Many thanks in advance,

Bill Planey
 
D

Doug Robbins

Why not just convert the table to text and then use a wildcard search and
replace to replace consecutive tabs with a single tab?

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
B

Bill Planey

Why not just convert the table to text and then use a wildcard search and
replace to replace consecutive tabs with a single tab?


Because, as I said, some instances of consecutive tabs need to be preserved
and some don't. That's why the intelligence to put a placeholder string in
_certain_ empty cells is desirable.

Bill Planey
 
B

Bill Planey

Thanks, I'll try that.

Bill


Word tables get seriously tricky if you have merged or split cells. Without
knowing the logic of when you want to preserve the cells and when you don't
it's hard to offer specific suggestions. Are you familiar with the RowIndex
and ColumnIndex properties? You can use these to recognise if a cell is
merged or split, and they are always available -- unlike the Row and Column
properties.

To get a feel for what's going on, create a table with some merged and split
cells of the sort of complexity your code has to deal with. Put some
recognizable text into each cell, then run the following --

Dim pCell As Word.Cell

Set pCell = ActiveDocument.Tables(1).Cell(1, 1)
Do
Debug.Print Left$(pCell.Range, Len(pCell.Range) - 2), _
pCell.RowIndex, pCell.ColumnIndex
Set pCell = pCell.Next
Loop Until pCell Is Nothing


You've probably worked it out already: a cell is empty if the length of its
range = 2 -- a cell always contains vbCr Chr(7)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top