• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

bVisual

  • Home
  • Services
    • How Visio smartness can help your business
    • Visio visual in Power BI
    • Visio Consulting Services
    • Visio Bureau Services
    • Visio Training and Support Services
  • Products
    • Visio Shape Report Converter
    • SS Plus
    • LayerManager
    • visViewer
    • Metro Icons
    • Rules Tools for Visio
    • The Visio 2010 Sessions App
    • Multi-Language Text for Visio
    • Document Imager for Visio
    • multiSelect for Visio
    • pdSelect for Visio
  • Case Studies
    • Case studies overview
    • Visualizing Construction Project Schedules
    • Visio Online Business Process Mapping
    • Nexans Visio Template
    • CNEE Projects, WorldCom
    • Chase Manhattan Bank
  • News
    • Recent news
    • News archive
  • Resources
    • Articles➡
      • ShapeSheet Functions A-Z
      • Comparing Visio for the Web and Desktop
      • Customising Visio Shapes for the Web App
      • Key differences between the Visio desktop and web apps
      • Using the Visio Data Visualizer in Excel
      • Using Visio in Teams
      • Creating Visio Tabs and Apps for Teams with SharePoint Framework (SPFx)
      • Designing Power Automate Flows with Microsoft Visio
      • Innovative uses of Visio Lists
    • Webcasts ➡
      • Visio in Organizations
      • My session and other Visio sessions at MSIgnite 2019
      • Power up your Visio diagrams
      • Vision up your Visio diagrams
      • The Visio 2010 MVP Sessions
    • Visio Web Learning Resources
    • Books➡
      • Mastering Data Visualization with Microsoft Visio
      • Microsoft Visio Business Process Diagramming and Validation
      • Visualizing Information with Microsoft Visio
  • Blog
    • Browse blog articles
    • Visio Power BI articles
    • Visio for Web articles
    • A history of messaging and encryption
  • About us
    • About bVisual
    • Testimonials
    • Bio of David Parker
    • Contact Us
    • Website Privacy Policy
    • Website terms and conditions
    • Ariba Network
You are here: Home / Visio / Displaying the Master and Stencil Name of Shape

Published on August 3, 2009 by David Parker

Displaying the Master and Stencil Name of Shape

A recent newsgroup question asked if it is possible to display the master name and the stencil that a shape originally came from.   Following on from my last post ( Re-opening Default Stencils ), I realised that this is possible  Here’s how (once you have created a reference to the Microsoft Scripting Runtime):

Public Sub DisplayOriginalMaster()

If Visio.ActiveWindow.Selection.Count = 0 Then
Exit Sub
End If
Dim shp As Visio.Shape
Set shp = Visio.ActiveWindow.Selection.PrimaryItem
If shp.Master Is Nothing Then
MsgBox “This shape has no master”, vbExclamation
Exit Sub
End If

Dim mst As Visio.Master
Set mst = shp.Master
Dim stenName As String
stenName = getStencilName(mst.UniqueID)
If Len(stenName) = 0 Then
MsgBox “Sorry, I can’t find the stencil this master (” & mst.Name & “) is from”, vbExclamation
Else
MsgBox “This shape is the master : ” & mst.Name & vbCrLf & “is from the stencil : ” & stenName, vbExclamation
End If

End Sub

Private Function getStencilName(ByVal mstID As String) As String

Dim srcDoc As Visio.Document
Set srcDoc = Visio.ActiveDocument
Dim tmplt As String
tmplt = srcDoc.Template
If Len(tmplt) = 0 Then
Exit Function
End If

Dim fs As FileSystemObject
Set fs = New FileSystemObject
If fs.FileExists(tmplt) = False Then
Exit Function
End If
Dim winSrc As Visio.Window
Dim stenDoc As Visio.Document
Dim aryStens() As String
Dim win As Visio.Window
Dim arySrcStens() As String
For Each win In Visio.Windows
If win.Document Is srcDoc Then
Set winSrc = win
winSrc.DockedStencils arySrcStens
Exit For
End If
Next

Dim sten As String
Dim stenName As String
Dim i As Integer
For i = 0 To UBound(arySrcStens)
stenName = stenContains(arySrcStens(i), mstID)
If Len(stenName) > 0 Then
getStencilName = stenName
Exit Function
End If
Next
Dim doc As Visio.Document
Set doc = Visio.Application.Documents.OpenEx(tmplt, Visio.visOpenCopy + Visio.visOpenHidden + Visio.visOpenDontList)

For Each win In Visio.Windows
If win.Document Is doc Then
win.DockedStencils aryStens
End If
Next
For i = 0 To UBound(aryStens)
stenName = stenContains(aryStens(i), mstID)
If Len(stenName) > 0 Then
Exit For
End If
Next
‘Close the template document
doc.Close

getStencilName = stenName
End Function

Private Function stenContains(ByVal sten As String, ByVal mstID As String) As String
Dim doc As Visio.Document
Dim mst As Visio.Master
For Each doc In Visio.Application.Documents
If doc.FullName = sten Then
For Each mst In doc.Masters
If mst.UniqueID = mstID Then
stenContains = doc.Title
Exit Function
End If
Next
End If
Next
stenContains = “”
End Function

Related

Filed Under: Visio

About David Parker

David Parker has 25 years' experience of providing data visualization solutions to companies around the globe. He is a Microsoft MVP and Visio expert.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

  • LinkedIn
  • Twitter

Recent Posts

  • Update to LayerManager add-in for non-English users
  • Pushing Data Visualizer in Visio beyond its limits
  • Pushing Data Visualizer in Visio to the limits!
  • Teams Tuesday Podcast Recording about Visio
  • Linking Data to Visio Shapes in Code

Categories

Tags

Accessibility Add-Ins Connectors Containers Data Export Data Graphics Data Import Data Visualizer Educational Excel GraphDatabase Hyperlinks Icon Sets JavaScript Layers Legend Link Data to Shapes Lists MSIgnite MVP Office365 Org Chart PowerApps PowerBI PowerQuery Processes Shape Data Shape Design ShapeSheet ShapeSheet Functions SharePoint 2013 SQL Teams Themes Validation VBA Video Visio Visio 2007 Visio 2013 Visio for the Web Visio Online Visio Services Visio Viewer Webinar

Footer

bVisual Profile

The UK-based independent Visio consultancy with a worldwide reach. We have over 25 years experience of providing data visualization solutions to companies around the globe.

Learn more about bVisual

  • LinkedIn
  • Twitter

Search this website

Recent posts

  • Update to LayerManager add-in for non-English users
  • Pushing Data Visualizer in Visio beyond its limits
  • Pushing Data Visualizer in Visio to the limits!
  • Teams Tuesday Podcast Recording about Visio
  • Linking Data to Visio Shapes in Code

Copyright © 2023 · Executive Pro on Genesis Framework · WordPress · Log in