Search for grouped clipart and text

G

Geoff

I am looking for assistance on searching on shape objects. I have
grouped clipart and a textbox that I am trying to search on. The code
below works when I manually search, but I would like to automate this
process. I have the grouped images anchored to text. I want to align
all of these "icons". Can someone steer me in the right direction?

Once The search is complete I want to align with the following:

Selection.ShapeRange.RelativeHorizontalPosition = _
wdRelativeHorizontalPositionColumn
Selection.ShapeRange.RelativeVerticalPosition = _
wdRelativeVerticalPositionParagraph
Selection.ShapeRange.Left = InchesToPoints(0.5)
Selection.ShapeRange.Top = InchesToPoints(0.1)
Selection.ShapeRange.LockAnchor = False
Selection.ShapeRange.WrapFormat.AllowOverlap = False

Then cycle through to the end. Any help would be great.

TIA

Geoff
 
J

Jay Freedman

Hi Geoff,

Using the Selection object for this is definitely doing it the hard
way. VBA has a standard mechanism, the For Each loop, for walking
through an entire collection of objects. In this case, the collection
is ActiveDocument.Shapes. The code looks like this:

Dim oShp As Shape
For Each oShp In ActiveDocument.Shapes
With oShp
.RelativeHorizontalPosition = _
wdRelativeHorizontalPositionColumn
.RelativeVerticalPosition = _
wdRelativeVerticalPositionParagraph
.Left = InchesToPoints(0.5)
.Top = InchesToPoints(0.1)
.LockAnchor = False
.WrapFormat.AllowOverlap = False
End With
Next oShp
 
G

Geoff

Hi Jay,

Thanks for the quick reply. Your suggestion was right on target.
Unfortunately, I seem to have other grouped objects in my document that
are getting picked up as well. Since I think it's an all or nothing
situation, I will try and modify when and where this routine is used.

Thanks again.
 
J

Jay Freedman

Geoff said:
Hi Jay,

Thanks for the quick reply. Your suggestion was right on target.
Unfortunately, I seem to have other grouped objects in my document
that are getting picked up as well. Since I think it's an all or
nothing situation, I will try and modify when and where this routine
is used.

Thanks again.

Hi Geoff,

Within the code I showed, you can limit the changes to only certain objects
by placing an If ... Then ... End If clause around the inner part of the
loop. The trick then is to define the proper expression for the If
statement.

For example, if the shapes you want to format are just the ones whose
anchors are in paragraphs with Body Text style, you can express it this way:

Dim oShp As Shape
For Each oShp In ActiveDocument.Shapes
If oShp.Anchor.Style = "Body Text" Then
With oShp
.RelativeHorizontalPosition = _
wdRelativeHorizontalPositionColumn
.RelativeVerticalPosition = _
wdRelativeVerticalPositionParagraph
.Left = InchesToPoints(0.5)
.Top = InchesToPoints(0.1)
.LockAnchor = False
.WrapFormat.AllowOverlap = False
End With
End If
Next oShp

Any shapes that are in paragraphs with other styles won't be formatted.

Try to figure out a condition that's true for the shapes you do want to
move, and is false for the ones you don't want to move.
 
G

Geoff

Thank you Jay! Your solution worked perfectly. I was going to wimp
out and do the routine in only certain files before I assembled them,
but your solution pushed me into doing the better way. Since I had
only two different styles tied to the grouped clipart, I did a nested
if then (my first in VBA) statement.

Thanks for your follow up.

Geoff
 

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