how correctly create group from selected shapes in VBA

Started by Surrogate, May 28, 2010, 01:00:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Surrogate

Hi all,

i need selected few shapes and create group from this shapes. These shapes located in some file. I write macros,


Function GetRacks()
On Error GoTo errHandle
Dim X As Integer
Debug.Print Path
Application.Documents.OpenEx "D:\RACKS\2.vsd", visOpenRO
Application.ActiveWindow.SelectAll
ActiveWindow.DeselectAll
For X = Application.ActiveWindow.Page.Shapes.Count To 1 Step -1
Debug.Print X
ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(X), 1024
Next X
Application.ActiveWindow.Selection.group
Application.ActiveWindow.Selection.Copy
Application.ActiveWindow.Close
Exit Function
errHandle:
MsgBox Err.Description, vbCritical, "Error №" & Err.Number
End Function

Sub MACRO1()
GetRacks
Application.ActiveWindow.Page.Paste
End Sub


when i tried to use code: Application.ActiveWindow.Selection.group
i have got error 2032465766


Please tell me, how correctly create group from selected shapes in VBA ?

Thanks.


Jumpy

Hi,
I made a test with the makro editor:

Sub Macro1()
    ActiveWindow.DeselectAll
    ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(1), visSelect
    ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(2), visSelect
    ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(3), visSelect
    ActiveWindow.Selection.Group
End Sub


It seems, that your grouping line is correctly, but what is with the selection?
Whats with 1024? The makro editor usues visSelect which only equals 2.
Looking in the Visio VBA help and adding all the possible numbers for that constant, I get at max 266.

Jumpy

Jumpy

It's definetivly the 1024.

I replaced the visSelect in the Code of the Makro Editor with 1024 (after manually ungrouping the shapes) and got the same error message you got.
Maybe because the selection is empty.
Using visSelect (=2) again, it worked.

Jumpy

Surrogate

#3
hi,

in my case i have a lot of different files. i don`t know how many shapes and groups include in each.

code 1024 mean visSelModeSkipSub. i read about this case in article by VisioGuy
http://www.visguy.com/2008/05/17/detect-sub-selected-shapes-programmatically

when i change code
ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(x), visSelect ' wrong code

ActiveWindow.Select Application.ActiveWindow.Page.Shapes(x), visSelect ' right code
i havn`t got this error message!

after this changes, i tried selected shapes in some test file with modes of selection: visSelectall and visSelModeSkipSub. Sets of selection shapes was same.

thank you, Jumpy! Now i have got help from russian Visio`s Guru, and finished my macros :)