PDA

View Full Version : Word TexBox nightmare



cjperks
04-29-2010, 01:38 AM
Hi there

I've been searching for help on this specific problem for a few days now with no luck so far, so I hope someone here can help me!

At present I'm working with some appallingly designed word documents that contain masses of data that at present I have to copy out manually :(

The pages at first appeared to be a collection of tables, so sorting through them cell by cell looking for the relevant keywords and data was not that scary a task - however...

The pages are actually a collection of grouped TextBoxes that contain within them some tables.

I've managed to ungroup/regroup the Textboxes using the shape.ungroup/regroup commands but trying to extract the tables from the text boxes seems to be impossible.

I can get the text out of the textbox as a big lump using the Shapes.AlternativeText but I can't convert this back to a usable table at present either.

The Shapes.AlternativeText still retains some of the tables formatting in the form of tab spaces so this might be a way foreward...

Any help would be massively appreciated.


Chris...

fumei
04-29-2010, 11:45 AM
"The pages are actually a collection of grouped TextBoxes that contain within them some tables."

Oh my gosh.

"appallingly designed word documents"

is putting it mildly. I truly sympathize!

Is there any way you can post a sample document? Stripped of anything you do not want to be seen of course.

In the meantime I can try to start duplicating the mess, although, I completely despise textboxes, especially when used like this. If I understand correctly, these are textboxes, and IN the textboxes are tables...yes?

fumei
04-29-2010, 11:46 AM
BTW: you can not post/upload until you have a minimum of 5 posts...so post a few blah blah blah so you can upload a file (if this is possible).

cjperks
04-30-2010, 12:21 AM
Yes, you are correct Gerry, there are text boxes, and INSIDE (shudder) there are tables(s).

To duplicate my situation, make a new document, insert a text box, click inside the textbox, insert a table. Copy this whole arrangement a few times then group them all into one big shape.

Then make yourself 60+ pages of this arrangement.

Then try to pull data off the tables on a page by page basis in some coherent form....

I'm glad someones replied, even just to agree how horrific it is, I thought I was the only one!


I'll post a copy of one of the documents when I'm allowed.

Thanks for cheering me up!


Chris

cjperks
04-30-2010, 12:36 AM
In fact, if you want an example, here's a link to one of the files, with all the data blanked out of course ;)

dl.dropbox.com/u/2679305/textboxesfromhell.docx

Have fun! :banghead:

fumei
04-30-2010, 02:29 PM
BTW: to others, the OP has cross-posted this to:

http://www.officekb.com/Uwe/Forum.aspx/word-vba/24782/Word-TextBox-nightmare

Yikes....this is difficult!

cjperks
05-01-2010, 04:29 AM
You're telling me! :(

I've spent nearly two working days trying to find ways round this (don't tell the boss ;) ) and I've still not come up with anything useful. I'm learning lots about office and VBa along the way, but nothing approaching a solution yet :'(

I'm glad its not just me thats being confused by all this...

I would post some of the code I've produced, but it wouldn't help at present :(

Chris...

fumei
05-03-2010, 08:23 AM
I am having a very hard time with this, and no real movement yet.


Tony????

cjperks
05-05-2010, 06:59 AM
Don't worry about it guys, if this is taking ages it probably just cant be done. I'll have to find another way round it.

I don't want to be wasting your time.

Chris...

fumei
05-05-2010, 09:39 AM
It is not really a waste of time...it is a challenge. I am starting to suspect, though, that it may not be possible. I have not yet been able to access the tables as individual objects. If I could, that would solve it, but so far...no luck. I must admit I have put this aside for a bit as I am busy doing "real" work.

I certainly would not hold your breath. Move on, as you must.

cjperks
05-07-2010, 04:26 AM
Its sad that one of the most commonly used programs in the world will happily let you mess things up so badly they cannot be undone...

Insert Table inside TextBox = No

Who is this "Tony" of which you speak? A wizard of old?

(I've got an image in my head of Neo from the Matrix - but he lives inside VBA instead... >< )

Chris...

fumei
05-07-2010, 09:25 AM
No, Tony Jollans who visits here. He is probably busy, but I may send a PM to him to see if he would look at this. More for my own selfish benefit as I am rather stumped on this. If Tony can not get a way to access those table objects, then I am willing to accept that it can not be done.

BTW: I hate hate hate hate textboxes, and one of the reasons is precisely this. It makes programmable access to contents very messy.

In that vein..

"Its sad that one of the most commonly used programs in the world will happily let you mess things up so badly they cannot be undone..."

Except you are not really trying to undo anything, really. This is an object model exercise, and the issue (I think) is that you are trying to access a text-type object (essentially a table is text with lined paragraph boundaries) that is on a graphics layer.

To give a painful illustration...my boss is blind. He is very effective with his screen reader, but it does NOT read the graphics layer of Word documents. So his boss sent him a Word document that is, wait for it, 100% in the graphics layer!!!

It is 8 pages long, and if you do a Word count, it has 0 words, 0 paragraphs. Every single piece of text is in textboxes. Everything.

There is nothing his screen reader can read.

TonyJollans
05-07-2010, 10:28 AM
The trick with this kind of stuff is to drill gradually down. I'm not sure what you may have altogether so there may be a lot more to code for, and I don't know what you want to do with the text when you've found it, but here's a start ...

Dim Outer As Word.Shape
Dim Inner As Word.Shape
Dim InnerRange As Word.Range
Dim InnerTable As Word.Table
Dim InnerCell As Word.Cell
Dim CellRange As Word.Range

Set Outer = ActiveDocument.Content.ShapeRange(1)

Select Case Outer.Type
Case msoGroup
For Each Inner In Outer.GroupItems

Select Case Inner.Type

Case msoTextBox
Set InnerRange = Inner.TextFrame.ContainingRange

For Each InnerTable In InnerRange.Tables
For Each InnerCell In InnerTable.Range.Cells
Set CellRange = InnerCell.Range
CellRange.MoveEnd wdCharacter, -1
If Len(CellRange.text) > 0 Then
Debug.Print CellRange.text
End If
Next
Next InnerTable

Case msoLine ' Ignore
Case Else:
MsgBox "Something else to check for!"
End Select

Next Inner

Case Else
MsgBox "Something else to check for!"

End Select

fumei
05-07-2010, 11:08 AM
ContainingRange!!

I knew Tony would find something. I never knew about ContainingRange, as I never use it. THAT is what is holding the tables.

Thanks Tony. It was making me nuts.

fumei
05-07-2010, 11:53 AM
You may have an issue with merged cells.

However, with the expert knowledge of Tony, here is a non-2007 version (textboxfromhell.doc), and a Document_Open event that grabs the text from the cells you indicate as important, and displays the cell contents as:

And these
Are
The
Important
Ones!

So, yes, it CAN be done. You will obviously have to fuss a bit, but it is quite do-able.

cjperks
05-10-2010, 02:18 AM
THANKYOU TONY!

You have no idea how happy you have just made me.

This is possibly the best (work) since the day I started 7 months ago - no, not possibly, definitely.

Being able to get into these cells means I can start to strip these pages apart and get the the information from an 80 page report at the push of a button!

Tony:- If I'm ever down the Norfolk way I owe you a nice case of wine/beer. And as summer is coming up this is actually a very real possibility!

fumei:- I hope your curiosity is satisfied now! :D Thankyou for all your help and getting Tony involved! I fear your beer will have to wait a little longer as I'm not sure I'll be getting over to B.C. for another year or two.

Thankyou again,

Chris...
:bow:

TonyJollans
05-10-2010, 03:42 AM
My pleasure. I'll look forward to the summer!

cjperks
05-13-2010, 08:21 AM
Hi Guys,

Just a follow up:

The program is well on its way now, that little bit of code works perfectly and I can navigate around, and manipulate data from, all the cells within each evil little textbox.

Couple of hundred lines lines down on the screen, a couple hundred more to go!

Thanks again!

(I'm sure I'll be back asking for (or giving) help before long ;))

Chris...