Visio Guy

Visio Discussions => General Visio => Topic started by: ToninoS on October 26, 2020, 02:36:06 AM

Title: macro to set shape style
Post by: ToninoS on October 26, 2020, 02:36:06 AM
Hi all, does anyone know if it is possible to either:
1) have a shape change style based on shape data input for the shape that matches name of  or if not
2) have a shape or all shapes in a drawing change style based on a macro that looks at shape data?
Cheers all :)
Title: Re: macro to set shape style
Post by: Surrogate on October 26, 2020, 04:20:23 AM
1) have a shape change style based on shape data input for the shape that matches name of  or if not
This code add to ShapeData row with list of styles which used in this document.
Code
Sub AddStyleListToShape1()
Dim st As Style, stn As String, sh As Shape, nnn As String
stn = ""
For Each st In ThisDocument.Styles
stn = stn & ";" & st.Name
Next
Set sh = ActivePage.Shapes(1)
If Not sh.SectionExists(visSectionProp, visExistsAnywhere) Then
sh.AddSection visSectionProp ' add Shape Data section
sh.AddRow visSectionProp, 0, 0 ' add new row to Shape Data
sh.Cells("prop.row_1.type").FormulaU = 1 ' make fixed style list
sh.Cells("prop.row_1.format").FormulaU = Chr(34) & stn & Chr(34)
sh.Cells("prop.row_1.value").FormulaU = "INDEX(1,Prop.Row_1.Format)"
End If
End Sub
Title: Re: macro to set shape style
Post by: ToninoS on October 27, 2020, 12:27:20 AM
Surrogate, thank you :) which column would i try this in? or would this go in VBA for the sheet?
Title: Re: macro to set shape style
Post by: Surrogate on October 27, 2020, 05:52:40 AM
Hi, Tonino !
Please try my attached document.
1. select shape
2. start macro AddStyleListToShape1 for update styles list for document (at my side i have Style names in Russian language)
3. change shape data and check used styles
Title: Re: macro to set shape style
Post by: ToninoS on October 27, 2020, 05:57:08 AM
HEY, that is great, thank you for that Surrogate :)    i can find my way through excel VBA but visio is another beast it seams :)