Find/delete all shapes added from external files (.emf files)



I have an orgchart, and I'm bringing in some .emf files and placing them in
the orgchart behind the existing orgchart shapes. This is all done in code.

Normally I have to rebuild the orgcharts because they change each month,
then add shapes to the new orgchart.

In this case, I need to update the same orgchart by replacing those added
shapes with revised ones, so I'm looking for the easiest way to loop through
every shape on every page, and delete anything that was imported as an .emf
file (imported using the following code, if it matters):

With Application.ActiveWindow
Set vsoShape = .Page.Import(MyFileName2)
On Error GoTo 0
vsoShape.Cells("PinX").FormulaU = b1
vsoShape.Cells("PinY").FormulaU = LowerPinY
vsoShape.Cells("Height").FormulaU = HalfHeight
vsoShape.Cells("Width").FormulaU = b4
End With

I'm good with VBA in Excel, but I don't know much about the Visio object
model, so I'm not sure how to actually determine if a selected shape is one
of these .emf images, vs. and org chart shape vs. a connector line, etc.

Any suggestions?

Thank you!




I'm still interested in how to flag these shapes when they are loaded, but in
the meantime I found that this code will remove all the shapes on my sheets.
That includes a shape or two that I didn't want removed, but it is much
faster to replace those than to delete these other shapes by hand or worse,
have to recreate the org charts.

Sub RemoveMyShapes()
ShpsCount = Application.ActivePage.Shapes.Count
Set shpsObj = Application.ActivePage.Shapes ' root.Shapes
For UseShpObj = ShpsCount To 1 Step -1
Set shpObj = shpsObj(UseShpObj)
If Left(shpObj.Name, 6) = "Sheet." Then shpObj.Delete
End Sub



John Goldsmith_Visio_MVP

Hello Keith,

I agree with Al on adding a field to your image shapes as you drop them on
the page, but you might also be interested in the ForeignType property of
the Shape object. This tells you if you've got hold of a meta file, or
bitmap etc. I don't think you can tell whether it's an emf or wmf (unless
you want to start reading the meta data itself and I'm not sure if you can)
or whether it's a jpeg or bmp but that maybe enough in your situation.

By the way, be careful of using the local Name property of a shape rather
than the universal NameU property. Here's some info if you're interested:

Best regards


John Goldsmith (Visio MVP)