Visio Guy

Visio Discussions => Programming & Code => Topic started by: Visisthebest on July 21, 2020, 03:14:45 PM

Title: Running the macro recorder using the Format Painter generates no code
Post by: Visisthebest on July 21, 2020, 03:14:45 PM
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!

Title: Re: Running the macro recorder using the Format Painter generates no code
Post by: Surrogate on July 22, 2020, 04:30:27 AM
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?
Title: Re: Running the macro recorder using the Format Painter generates no code
Post by: Visisthebest on July 22, 2020, 07:32:12 AM
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!
Title: Re: Running the macro recorder using the Format Painter generates no code
Post by: Surrogate on July 22, 2020, 07:54:45 AM
I create custom style named 'ololo' this simple code apply change style for selected shape
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 (https://veithen.io/2013/05/09/using-styles-in-microsoft-visio.html)!


Title: Re: Running the macro recorder using the Format Painter generates no code
Post by: Surrogate on July 22, 2020, 08:06:59 AM
My answer in thread about Styles in Visio
Quote from: Can't create a new style (https://social.technet.microsoft.com/Forums/office/en-US/60a0ec33-e2a3-4c0f-9383-a3b40056585a/cant-create-a-new-style)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'
(https://social.technet.microsoft.com/Forums/getfile/1471429)
If you use Visio 2010/2013 look at answer in that thread in SuperUser forum (https://superuser.com/questions/226521/how-can-i-change-the-default-properties-of-visios-connector-tool/1325316#1325316).

(https://social.technet.microsoft.com/Forums/getfile/1471431)
In 'Define style' window you must enter some name for your style and after that you must press button 'Add'
Title: Re: Running the macro recorder using the Format Painter generates no code
Post by: Visisthebest on July 22, 2020, 09:04:46 AM
Thank you Surrogate this is exactly what I'm looking for! Why are so many Visio goodies hidden from users by default?
Title: Re: Running the macro recorder using the Format Painter generates no code
Post by: Visisthebest on July 22, 2020, 09:05:52 AM
Can I store styles in a stencil?
Title: Re: Running the macro recorder using the Format Painter generates no code
Post by: Surrogate on July 22, 2020, 10:01:33 AM
Quote from: Visisthebest on July 22, 2020, 09:04:46 AM
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.
(https://raw.githubusercontent.com/Surrogate-TM/surrogate-tm.github.io/master/own/pics/2003_interface/0_Toolbars_2003.png)
2. MS mean that all these hidden goodies are obsolete !
Title: Re: Running the macro recorder using the Format Painter generates no code
Post by: Surrogate on July 22, 2020, 10:08:09 AM
Quote from: Visisthebest on July 22, 2020, 09:05:52 AM
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!
Title: Re: Running the macro recorder using the Format Painter generates no code
Post by: Visisthebest on July 22, 2020, 03:28:32 PM
Ok great so added automatically when a master uses a style! :)