loop to act on one object at a time...

I

Ivano

Hi,
I have a number of objects that I pasted special from Excel in Word and have
written a macro to adjust its properties. However, anytime the size is
adjusted with multiple objects selected it takes all the objects, which are
on different pages, and puts them on top of each other on one page. This
will happen even if you select all the objects and manually adjust the size
by right clicking > properties > size > and picking your size.
For example
If I have selected 3 objects with three different settings changes that need
to be done and run the macro this is what happens

object 1, adjust the first property>
object 2, adjust the first property>
object 3 ,adjust the first propery

object 1, adjust the second property>
object 2, adjust the second property>
object 3 ,adjust the second propery

object 1, adjust the third property>
object 2, adjust the third property>
object 3 ,adjust the third propery

What I think I need is
go to object 1, adjust the first, second, third property>
go to object 2, adjust the first, second, third property>
go to object 3, adjust the first, second, third property

So, I'm thinking that I have to create a loop that will adjust all the
properties of each object one a time. What kind of loop do I need and what is
the syntax?

Hope this all makes sense....
Thanks
 
J

Jezebel

Dim pShape as Word.Shape

For each pShape in ActiveDocument.Shapes
With pShape
.Height = ...
.Width = ...
:
End with
Next

This assumes you have no other shapes in the document. If you do, you'll
need to test whether it's a shape you want to adjust.
 
I

Ivano

Hi Jezebel,
thanks.... however, I do have other shapes. But what I can do is select all
the shapes I want and then tell it to run the macro against the range of
shapes selected.
Here is the code I have so far:

Selection.ShapeRange.Fill.Visible = msoFalse
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.Transparency = 0#
Selection.ShapeRange.Line.Weight = 0.75
Selection.ShapeRange.Line.DashStyle = msoLineSolid
Selection.ShapeRange.Line.Style = msoLineSingle
Selection.ShapeRange.Line.Transparency = 0#
Selection.ShapeRange.Line.Visible = msoTrue
Selection.ShapeRange.Line.ForeColor.RGB = RGB(0, 0, 0)
Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
Selection.ShapeRange.LockAspectRatio = msoFalse

Selection.ShapeRange.Left = 54#
Selection.ShapeRange.Top = 187.2
Selection.ShapeRange.RelativeHorizontalPosition = _
wdRelativeHorizontalPositionColumn
Selection.ShapeRange.RelativeVerticalPosition = _
wdRelativeVerticalPositionPage
Selection.ShapeRange.Left = wdShapeCenter
Selection.ShapeRange.Top = InchesToPoints(2.6)
Selection.ShapeRange.LockAnchor = False
Selection.ShapeRange.WrapFormat.AllowOverlap = True
Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
Selection.ShapeRange.WrapFormat.DistanceTop = InchesToPoints(0)
Selection.ShapeRange.WrapFormat.DistanceBottom = InchesToPoints(0)
Selection.ShapeRange.WrapFormat.DistanceLeft = InchesToPoints(0.13)
Selection.ShapeRange.WrapFormat.DistanceRight = InchesToPoints(0.13)
Selection.ShapeRange.WrapFormat.Type = wdWrapTopBottom


' sets Height to 6" and Width to 7" 1"~72pts
'Selection.ShapeRange.Height = 432
'Selection.ShapeRange.Width = 504
 
J

Jezebel

Well that explains your problem: you select all the shapes and set them so
they are all positioned in the same place. Exactly as described. Do you not
like the suggested solution?
 
I

Ivano

Hi Jezebel,
Sorry if I didn't explain myself properly but I modified the code to read :

Dim pShape As Word.Shape
For Each pShape In Selection.ShapeRange
With pShape
.Height = 396
.Width = 540
End With
Next

This worked the way I wanted to.
Thanks for your code
 

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