summarise document contents

  • Thread starter Alastair MacFarlane
  • Start date
A

Alastair MacFarlane

Dear Group

How in Word can I loop through a document and get the dimensions and
position of every object on the page, be it paragraph, rectangle, line, etc.
I can loop through text and paragraphs as below, but I need all objects on a
page.

Dim para As Paragraph
For Each para In ActiveDocument.Paragraphs
****
Next


What I really want is the Left, Top, Height and Width of the object and the
TypeOf object it is.

I have over 50 documents of 5 or more pages looking like forms (30 Boxes and
lines) that I want all the measurements so I can take these measurements and
create the same objects in a VB form. My aim is to create a converter. I
fully appreciate that the same objects do not exist in VB so I will use
CreateControl to create the comparable desired objects.

I realise this is a mammoth project but I would appreciate any pointers from
the group as to where to start.

Please help whilst I still have some hair!

Alastair MacFarlane
 
H

Helmut Weber

Hi Alastair,
not too difficult, only tedious.
And almost anything you see on a Word page is an object,
except e.g. characters, as I've learned just now,
which are range objects, representing one ore more characters.
Anyway, have a look at this one, as a start, with all kind of
improvements possible, whereby I leave analyzing the area,
a paragraph occupies on a page, to you.
Not to mention paragraphs, that reach over page breaks.

Sub Makro8()
' wdVerticalPositionRelativeToPage = 6
' wdHorizontalPositionRelativeToPage = 5
Dim iCount As Integer ' just a counter
Dim iShTyp As Integer ' the type of shape or of inlineshape
Dim iInlin As Integer ' number of inlineshapes
Dim iShape As Integer ' number of shapes
Dim sngTop As Single ' top
Dim sngLft As Single ' left
Dim sngHgt As Single ' height
Dim sngWdt As Single ' width
Dim sReslt As String ' the resulting string

iInlin = ActiveDocument.InlineShapes.Count
iShape = ActiveDocument.Shapes.Count
Debug.Print "Inlineshapes"
Debug.Print "### top left height width type"

With ActiveDocument.InlineShapes
For iCount = 1 To iInlin
.Item(iCount).Select
iShTyp = .Item(iCount).Type
sngTop = Selection.Information(6)
sngLft = Selection.Information(5)
sngHgt = .Item(iCount).Height
sngWdt = .Item(iCount).Width
sReslt = Format(iCount, "000 ")
sReslt = sReslt & Format(sngTop, "000.00 ")
sReslt = sReslt & Format(sngLft, "000.00 ")
sReslt = sReslt & Format(sngHgt, "000.00 ")
sReslt = sReslt & Format(sngWdt, "000.00 ")
sReslt = sReslt & Format(sngWdt, "000")
Debug.Print sReslt
Next
End With

Debug.Print "Shapes"
Debug.Print "### top left height width type"

With ActiveDocument.Shapes
For iCount = 1 To iShape
iShTyp = .Item(iCount).Type
sngTop = .Item(iCount).Top
sngLft = .Item(iCount).Left
sngHgt = .Item(iCount).Height
sngWdt = .Item(iCount).Width
sReslt = Format(iCount, "000 ")
sReslt = sReslt & Format(sngTop, "000.00 ")
sReslt = sReslt & Format(sngLft, "000.00 ")
sReslt = sReslt & Format(sngHgt, "000.00 ")
sReslt = sReslt & Format(sngWdt, "000.00 ")
sReslt = sReslt & Format(sngWdt, "000")
Debug.Print sReslt
Next
End With

End Sub

---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
A

Alastair MacFarlane

Helmut,

I am extremely impressed with the amount of time you must of spent on this
code. I appreciate your time. I will have a closer look at this code this
afternoon and no doubt I will have questions about its implementation.

Thanks

Alastair MacFarlane
 
H

Helmut Weber

Oops,
for the type, of course
sReslt = sReslt & Format(sngTyp, "000") ' !!!
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

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