Can't get type of object with macro

E

Ed

I was handed a report with a "table" in it. Somehow, either by deliberate
design or by document format conversions, the "table" became a collection of
lines and boxes! I'm working this in Word 2000. The "Select Multiple
Objects" button on the drawing toolbar showed lots of lines and rectangles,
with text assigned to the rectangles.

So I tried a macro to figure out what I've got; if I can find what property
of the shape is holding the text, I can probably get the text out and write
it into a real table. ActiveDocument.Shapes.Count gave me 332. Then I
tried:

Dim obj As Shape
Dim i As Long, j As Long
i = ActiveDocument.Shapes.Count

For j = 1 To j
ActiveDocument.Shapes(j).Select
Set obj = Selection
Debug.Print obj.Type
Next j

It errored on obj.Type!! I added On Error GoTo Next and it went through,
but never recognized the Type property of obj. I removed "As Shape", so obj
was just a Variant, and it gave me a Type number "8" - 332 times! Every
line and rectangle was a Type 8.

This is not a critical item - I've since retyped the whole table by hand!
But for learning purposes, how do I go about working through a situation
like this - trying to find out what I've got and how to work with it?

Ed
 
S

Stephanie Krieger

Hi, Ed,

You can check for text in the shape without worrying
about the shape type.

If Activedocument.shapes(x).TextFrame.HasText = True
Then ...

That shouldn't throw an error on the line shapes.

Hope that helps.

Best,
Stephanie Krieger
author of Microsoft Office Document Designer
blog: arouet.net
 
E

Ed

Thanks, Stephanie. That worked! I was able to "read" the text from the
shapes. Next step would be how to deal with it - I'll play with that when I
have time.

I think I figured out what happened - because I accidentally did it myself!
I just redid the whole table in Excel and then pasted it into Word as
Enhanced Metafile. It looked strangely familiar - sure enough, it was the
same thing! Unfortunately, there doesn't seem to be a way to easily reverse
the process!

Thanks again.
Ed
 

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