Thank you for your suggestion, WapperDude. I had thought about doing that
and after you suggested that, I went ahead and tried it. Here’s what I got:
Sub Macro1
ActiveWindow.DeselectAll
‘shape A
ActiveWindow.Select Application.ActiveWindo.Page.Shapes.ItemFromID(1),
visSelect
ActiveWindow.Select Application.ActiveWindo.Page.Shapes.ItemFromID(2),
visSelect
Application.ActiveWindow.Selection.Align visHorzAlignLeft, visVertAlignNone,
False
ActiveWindow.DeselectAll
‘shape B
ActiveWindow.Select Application.ActiveWindo.Page.Shapes.ItemFromID(3),
visSelect
ActiveWindow.Select Application.ActiveWindo.Page.Shapes.ItemFromID(4),
visSelect
Application.ActiveWindow.Selection.Align visHorzAlignRight,
visVertAlignNone, False
End Sub
I looked up the method visHorzAlign and this result, which confirms what we
did, but doesn’t help me further,
http://msdn.microsoft.com/en-us/library/ms367516.aspx.
I have no idea how to translate this into C#, but I could leave it as just a
macro if I can find a way to loop it so that no matter how many Shapes A and
B I have, it will align them.
Something like this maybe:
For (int i = 0; i<= NumA; i++)
{
ActiveWindow.Select Application.ActiveWindo.Page.Shapes.ItemFromID(i),
visSelect
Application.ActiveWindow.Selection.Align visHorzAlignLeft, visVertAlignNone,
False
}
For (int i = NumA; i<= NumB; i++)
{
ActiveWindow.Select Application.ActiveWindo.Page.Shapes.ItemFromID(i),
visSelect
Application.ActiveWindow.Selection.Align visHorzAlignLeft, visVertAlignNone,
False
}
I’ll have to check my VBA syntax of course, but since the program drops
items sequentially (ItemFromID) and drops all the A items first and B items
next, it should be fine for i to increment accordingly. What I don’t know
how to do is to find NumA and NumB.
A and B shapes come from a database and the data is linked to each shape.
Is there a VBA function to get the count or size of my linked database or
otherwise run queries on it from Visio?
Also, the align functions line the shapes up with respect to each other. Is
there a way to justify them all the way to one side? So that if they are all
dropped on the right side, I can push all of them to the far left side?
Many thanks for your help.