Author Topic: Running the macro recorder using the Format Painter generates no code  (Read 301 times)

0 Members and 1 Guest are viewing this topic.

Visisthebest

  • Full Member
  • ***
  • Posts: 149
I am trying to find out how to programmatically copy the styles (colors/gradients) from one shape to another, but when I run the macro recorder and do a copy-paste of styles from one shape to the next, the macro recorder generates no code other than this boilerplate code:

    'Enable diagram services
    Dim DiagramServices As Integer
    DiagramServices = ActiveDocument.DiagramServicesEnabled
    ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150

    'Restore diagram services
    ActiveDocument.DiagramServicesEnabled = DiagramServices

Any idea of how to copy over style settings from one shape to the next? Thank you for your help and advice!


Surrogate

  • Hero Member
  • *****
  • Posts: 1015
    • ShapeSheet™ Knowledge Base
You are right, not all actions can be write with macro recorder!

Do you use visio's build-in 'Styles'?

 Or just want make few shapes same?

Visisthebest

  • Full Member
  • ***
  • Posts: 149
I want to give users some options with respect to styles on subshapes in shapes in the stencil I made.

My idea was to store a few hidden shapes with different styles (that I use to paste style to the subshape in the master shapes I use), if the user chooses a different style I copy the relevant stencil master in to the document stencil then apply the chosen style to the subshape in this master then drop this master from the document stencil on to the page. The copy-paste styles would be ideal, minimum amount of code!
« Last Edit: July 22, 2020, 02:36:45 AM by Visisthebest »

Surrogate

  • Hero Member
  • *****
  • Posts: 1015
    • ShapeSheet™ Knowledge Base
I create custom style named 'ololo' this simple code apply change style for selected shape
Code
Dim sh As Shape
Set sh = ActiveWindow.Selection.PrimaryItem
sh.FillStyle = "Ololo"
sh.LineStyle = "Ololo"
sh.TextStyle = "Guide"
But only old-school Visio users remember about Styles!



Surrogate

  • Hero Member
  • *****
  • Posts: 1015
    • ShapeSheet™ Knowledge Base
My answer in thread about Styles in Visio
If you use Visio 2016/2019 or Visio Online Plan 2 you can write letters 'def' in field 'Tell me what do you want to do'

If you use Visio 2010/2013 look at answer in that thread in SuperUser forum.


In 'Define style' window you must enter some name for your style and after that you must press button 'Add'
« Last Edit: July 22, 2020, 03:11:30 AM by Surrogate »

Visisthebest

  • Full Member
  • ***
  • Posts: 149
Thank you Surrogate this is exactly what I'm looking for! Why are so many Visio goodies hidden from users by default?

Visisthebest

  • Full Member
  • ***
  • Posts: 149
Can I store styles in a stencil?

Surrogate

  • Hero Member
  • *****
  • Posts: 1015
    • ShapeSheet™ Knowledge Base
Why are so many Visio goodies hidden from users by default?
IMHO two reasons:
1. Ribbon interface need space more than Classic interface, because there is large and middle-size buttons. For example when you activate all toolbars in Visio 2003, it contain only little icons.

2. MS mean that all these hidden goodies are obsolete !
« Last Edit: July 25, 2020, 12:49:33 AM by Surrogate »

Surrogate

  • Hero Member
  • *****
  • Posts: 1015
    • ShapeSheet™ Knowledge Base
Can I store styles in a stencil?
Yes, you can distribute your custom styles with stencils.
If you store shapes with custom styles in stencil. After when you drop masters from stencil which use custom style, this action add copy of this style to target Visio document!

Visisthebest

  • Full Member
  • ***
  • Posts: 149
Ok great so added automatically when a master uses a style! :)
« Last Edit: July 24, 2020, 03:32:45 AM by Visisthebest »