Simple programming q

P

pallas

not hot on vba, is there a simpler way of doing this with variables?
ie coloring a bunch of shapes whose IDs are not consecutive without
selecting each in turn.

Public Sub changecolor()
Dim objshape As Visio.Shape

Set objshape = Visio.ActivePage.Shapes(2)
objshape.Cells("Fillforegnd") = 6

Set objshape = Visio.ActivePage.Shapes(6)
objshape.Cells("Fillforegnd") = 6

Set objshape = Visio.ActivePage.Shapes(33)
objshape.Cells("Fillforegnd") = 6

End Sub
 
P

pallas

the shapes are arranged on the page in groups which represent workpackages.
I know the Shape.ID of each shape, but since the shapes were not placed on
the page in order, the groups do not comprise shapes with consecutive IDs,
otherwise a for next loop would work.

ie the criteria is none other than eg I want to select shapes with ID 2, 6
and 33
 
M

Markus Breugst

So you want to loop through your selected shapes and change their color?
Then perhaps the following macro can give you a hint.

Best regards,
Markus

Public Sub ChangeColorOfSelectedShapes()
Dim myShape As Shape
Dim index As Integer

For index = 1 To ActiveWindow.Selection.Count
Set myShape = ActiveWindow.Selection.Item(index)
myShape.Cells("FillForeGnd").Formula = "2"
Next index
End Sub
 
J

John Marshall, MVP

P

pallas

This will only work when you are selecting shapes whose index numbers are
consecutive; I want to select a predetermined group.
 
J

John Marshall, MVP

Another possibility would be to assign a custom property to each shape that
represents the workpackage the shape belongs to. The code could then search
for shapes with a custom property that indicates the shape belongs to the
workpackage.

I'm just not big fan of using hard coded values (like shape 1, 2 and 33)
that can be volatile, unless it is a real Q&D solution.

John... Visio MVP

Need stencils or ideas? http://www.mvps.org/visio/3rdparty.htm
Need VBA examples? http://www.mvps.org/visio/VBA.htm
Common Visio Questions http://www.mvps.org/visio/common_questions.htm
 
M

Markus Breugst

This will only work when you are selecting shapes whose index numbers are
consecutive; I want to select a predetermined group.


Well, I guess you mix up "index" with "ID", but: The index of a selection
has nothing to do with the IDs of the selected shapes. You can select ANY
shapes in your drawing, independent of their IDs, and the macro will work.
Just try it.

Best regards,
Markus
 
P

pallas

Good thinking batman!
This is exactly what I will do...

I might be back if I can't sort the code out!

my aim is to animate the diagram so that workpackages light up according to
options...in the vague hope this will impress my peers.

Thanks John.
 

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