Visio Guy

Visio Discussions => ShapeSheet & Smart Shapes => Topic started by: kiler40 on October 21, 2014, 07:21:07 AM

Title: rename all shapes in a stencil
Post by: kiler40 on October 21, 2014, 07:21:07 AM
Hello All,
I have a stencil with a lot of shapes that i want to change their names all. Is there a way to do that ?

I was thinking of opening it somehow in xml variant... Or some macro.
Any ideas :/

Thanks in advance!
Title: Re: rename all shapes in a stencil
Post by: Surrogate on October 21, 2014, 08:09:01 AM
try this simple code
Sub ActiveDocumentMastersRename()
Dim counter As Integer, MasterName As String
counter = 1
Dim mst As Master
For Each mst In ActiveDocument.Masters
MasterName = "Master_" & counter
mst.Name = MasterName
counter = counter + 1
Next
End Sub
Title: Re: rename all shapes in a stencil
Post by: kiler40 on October 21, 2014, 09:34:41 AM
Henno surrogate,
Thanks for the quick response.
But this is changing the names in the document stencyl.  And i want to change in an externel stencyls.
Also the names are not randoom but related with a list.
Tjis is why i'm asking to find a way to get to the information and.. Replace it :)
Title: Re: rename all shapes in a stencil
Post by: Surrogate on October 21, 2014, 09:51:23 AM
Sub ExternalMastersRename()
Dim ex_m As Document
Set ex_m = Documents.OpenEx("c:\folder\your_master.vss", visOpenRW)
Dim counter As Integer, MasterName As String
counter = 1
Dim mst As Master
For Each mst In ex_m.Masters
MasterName = "Master_" & counter ' i don't know how you want rename your masters
mst.Name = MasterName
counter = counter + 1
Next
ex_m.Save
End Sub
Title: Re: rename all shapes in a stencil
Post by: kiler40 on October 21, 2014, 10:55:49 AM
Ok. This is one more step closer to te end.

Masters are called
202
203
204
Etc.

And i want to change to
750613
730205
.... Etc

And i have an comparison table.
Can i use something like replace command ?

Title: Re: rename all shapes in a stencil
Post by: Surrogate on October 21, 2014, 11:27:24 AM
Sub ExternalMastersRename_v02()
Dim ew As Object
Set ew = CreateObject("c:\path\your_list.xlsx") ' set there path to your table
Dim ex_m As Document
Set ex_m = Documents.OpenEx("c:\path\your_stencil.vss", visOpenRW)
' set there path to your master
Dim NewMasterName As String, MasterName As String
counter = 1
Dim mst As Master
For i = 1 To 1000 ' set there how many masters you want renamed
MasterName = ew.sheets(1).Cells(i, 1)
NewMasterName = ew.sheets(1).Cells(i, 2)
Set mst = ActiveDocument.Masters.Item(MasterName)
mst.Name = NewMasterName
Next
ex_m.Save
ex_m.close
set ex_m = Nothing
Set ew = Nothing
End Sub

PS in table first column contained current masternames, in second containes new masternames
Title: Re: rename all shapes in a stencil
Post by: kiler40 on October 21, 2014, 12:54:56 PM
This is the best !
Thanks!
Title: Re: rename all shapes in a stencil
Post by: Surrogate on October 21, 2014, 03:13:10 PM
Quote from: kiler40 on October 21, 2014, 07:21:07 AM
I was thinking of opening it somehow in xml variant...
what do you mean ?
i can rename masters by macro. but don't know how do it in xml stuffs  :(
Title: Re: rename all shapes in a stencil
Post by: kiler40 on October 21, 2014, 07:03:36 PM
Those were shots in the blind.
I work a lot with excel. Everything i can put in somehow tabular form... I can edit :)
I remember i have read a topic about saving shape sheet as xml and edit it. I was going in this direction.
But your macro do the job perfect.
I have added some rows to firs export all masters names in stencil order to avoid mistakes if the order in excel is mixed up somehow :) and then create the list according the stencil.

P.S.
Can i sort stencil alphabetically... Or numerous ?

Thanks for the help :)