Author Topic: macro to set shape style  (Read 184 times)

0 Members and 1 Guest are viewing this topic.

ToninoS

  • Jr. Member
  • **
  • Posts: 14
macro to set shape style
« 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 :)

Surrogate

  • Hero Member
  • *****
  • Posts: 1050
    • ShapeSheet™ Knowledge Base
Re: macro to set shape style
« Reply #1 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

ToninoS

  • Jr. Member
  • **
  • Posts: 14
Re: macro to set shape style
« Reply #2 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?
« Last Edit: October 27, 2020, 01:01:19 AM by ToninoS »

Surrogate

  • Hero Member
  • *****
  • Posts: 1050
    • ShapeSheet™ Knowledge Base
Re: macro to set shape style
« Reply #3 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

ToninoS

  • Jr. Member
  • **
  • Posts: 14
Re: macro to set shape style
« Reply #4 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 :)