• 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
    • Using Visio in Education for GIS
    • 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➡
      • Visualize Complex Processes with Microsoft Visio
      • 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 / Applying Selected DataGraphic to the Whole Document

Published on January 28, 2010 by David Parker

Applying Selected DataGraphic to the Whole Document

A recent newsgroup question asked if there is a way to apply a DataGraphic to all pages in a document.  Well, there is no built-in option in Visio 2007 (or Visio 2010), but it can be done with a little bit of VBA.  This blog presents a macro that can be used in most cases.

The specific use case was for an Organization Chart that has many pages, and it can be really tedious to make each page active, select all the shapes, then apply a DataGraphic, so I have written a macro that allows you to apply the required DataGraphic to a single shape, then you select that shape; run the macro to apply the same DataGraphic to all shapes in the document that has a Shape Data row with the same name as the the first Shape Data row in the selected shape.

The screenshots are from the Visio 2010 Beta, but the code will work for Visio 2007 Professional edition too.

image

Before


So, here is the macro that achieves the desired result:

   1: Option Explicit
   2:  
   3: Public Sub ApplyDataGraphicToDocument()
   4: Dim mstDG As Visio.Master
   5: Dim shp As Visio.Shape
   6: Dim pag As Visio.Page
   7: Dim firstProp As String
   8:  
   9:     If Visio.ActiveWindow.Selection.Count = 0 Then
  10:         MsgBox "Please select a shape which already has data graphics"
  11:         Exit Sub
  12:     Else
  13:         Set shp = Visio.ActiveWindow.Selection.PrimaryItem
  14:         If shp.DataGraphic Is Nothing Then
  15:             MsgBox "Please select a shape which already has data graphics"
  16:             Exit Sub
  17:         Else
  18:             'Get the shapes DataGraphic master
  19:             Set mstDG = shp.DataGraphic
  20:             'Get the name of the first Shape Data row
  21:             firstProp = "Prop." & _
  22:                 shp.CellsSRC(Visio.visSectionProp, 0, 0).RowNameU
  23:         End If
  24:     End If
  25:     
  26:     For Each pag In Visio.ActiveDocument.Pages
  27:         If pag.Type = visTypeForeground Then
  28:             For Each shp In pag.Shapes
  29:                 'Check that the named Shape Data row exists
  30:                 If shp.CellExistsU(firstProp, Visio.visExistsAnywhere) Then
  31:                     'Set the DataGraphic
  32:                     shp.DataGraphic = mstDG
  33:                 End If
  34:             Next
  35:         End If
  36:     Next
  37:  
  38: End Sub

image

After

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

You must be logged in to post a comment.

Primary Sidebar

  • LinkedIn
  • Twitter

Recent Posts

  • Co-authoring and Commenting with Visio Documents
  • Fixing dimensions of 2D shapes
  • Merging Linked Data from Similar Tables
  • Smart Radio Buttons and Check Boxes in Visio
  • Using Button Face Ids in Visio

Categories

Tags

Accessibility Add-Ins Connectors Containers Data Export Data Graphics Data Import Data Visualizer Educational Excel GraphDatabase Hyperlinks Icon Sets JavaScript LayerManager Layers Legend Link Data to Shapes Lists MSIgnite MVP Office365 Org Chart PowerApps PowerBI PowerQuery Processes Setup and Deployment Shape Data Shape Design ShapeSheet ShapeSheet Functions SharePoint 2013 SQL Teams Validation VBA Video Visio Visio 2007 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

  • Amazon
  • E-mail
  • Facebook
  • LinkedIn
  • Twitter
  • YouTube

Search this website

Recent posts

  • Co-authoring and Commenting with Visio Documents
  • Fixing dimensions of 2D shapes
  • Merging Linked Data from Similar Tables
  • Smart Radio Buttons and Check Boxes in Visio
  • Using Button Face Ids in Visio

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