Search code examples
c#office-addinsvisiostencils

Visio- How to hide Master from Stencil in run-time


Whether there is option to hide specific Master from Stencil in run-time? I tried mstr.Hidden = 1; and I got following exception: {"\n\nRequested operation is presently disabled."}.


Solution

  • It depends on the stencil you want to hide the master in. If it is not open-for-edit, then you can't set the Hidden property and hide the master.

    The stencils that Microsoft supplies with Visio are super-duper read-only. You can't even right-click on then and check the Edit Stencil property. It is disabled.

    However, if the stencil is your own stencil, or it is the Document Stencil for the document you are currently working on, then you can show and hide masters.

    Let's use the VBA Immediate window and do some investigation. I opened the standard Basic Flowchart template. It opens two stencils with the drawing. We can see their names as follows:

    ?Visio.Documents(1).Name
    '--> Drawing1
    
    ?Visio.Documents(2).Name
    '--> BASFLO_U.vssx
    

    The stencil BASFLO_U.vssx (Basic Flowchart Shapes) is the #2 document. It has a master called "Database". Let's try to hide it:

    Visio.Documents(2).Masters("Database").Hidden = true     
    
    '--> ERROR: Requested operation is presently disabled.
    '--> This is a Visio-supplied stencil, Read Only, and we can't edit it!
    

    If I drop "Database" into the drawing, the master will be copied to the Document Stencil of our working drawing. The active drawing is document #1. Make sure you have the Document Stencil visible, then type:

    Visio.Documents(1).Masters("Database").Hidden = True
    
    '--> The master disappears in the Document Stencil window
    

    Anyway, hope this is helpful, if not the greatest news.

    Why do you want to hide masters in the first place?