rename all shapes in a stencil

Started by kiler40, October 21, 2014, 07:21:07 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kiler40

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!

Surrogate

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

kiler40

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 :)

Surrogate

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

kiler40

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 ?


Surrogate

#5
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

kiler40


Surrogate

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  :(

kiler40

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 :)