• 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 / Displaying the RGB values of Shapes

Published on April 22, 2010 by David Parker

Displaying the RGB values of Shapes

Everyone knows that you can change the colour of Visio shapes.  Most people know that you can also change the fill pattern too.

image

The Fill dialog displays these bits of information as Color, Pattern and Pattern color.  However, the ShapeSheet stores them as FillForegnd, FillPattern and FillBkgnd.  The following screenshot is displaying the Values of the cells, which displays the RGB values:

image

The actual formula for a colour though, may reference a particular theme, or it could be a number from the color map, for example 2 usually means Red (or RGB(255,0,0)).

image

Some Visio users may wish to display the RGB values in Shape Data rows so that these values can be analysed or reported.

So, I have added some code to the bVisualUtilities.vss that I started in my last blog about automatically updating Shape Data with Area and Perimeter Lengths

First. I added some constants to the bVisualMetrics module:

Option Explicit
Const actionUpdateCell As String = "Actions.UpdateMetrics"
Const fillForegndCell As String = "Prop.FillForegnd"
Const fillBkgndCell As String = "Prop.FillBkgnd"
Const fillPatternCell As String = "Prop.FillPattern"

Then, I added the AddUpdateFillsTrigger() to add some cells to the Page and selected shapes.

Public Sub AddUpdateFillsTrigger()
Dim shp As Visio.Shape
Dim iSect As Integer
Dim iRow As Integer
Dim pag As Visio.Shape
    For Each shp In Visio.ActiveWindow.Selection
        If Not shp.ContainingMaster Is Nothing Then
            Set pag = shp.ContainingMaster.PageSheet
        ElseIf Not shp.ContainingPage Is Nothing Then
            Set pag = shp.ContainingPage.PageSheet
        End If
        iSect = Visio.VisSectionIndices.visSectionAction
        If pag.SectionExists(iSect, Visio.VisExistsFlags.visExistsAnywhere) = 0 Then
            pag.AddSection iSect
        End If
        If pag.CellExists(actionUpdateCell, Visio.visExistsAnywhere) = 0 Then
            iRow = pag.AddNamedRow(iSect, Split(actionUpdateCell, ".")(1), 0)
            pag.CellsSRC(iSect, iRow, Visio.VisCellIndices.visActionAction).FormulaU = _
                "=SETF(GetRef(Actions.UpdateMetrics.Checked)," & _
                    "NOT(Actions.UpdateMetrics.Checked))"
            pag.CellsSRC(iSect, iRow, Visio.VisCellIndices.visActionMenu).FormulaU = _
                "=""Refresh Metrics"""
        End If
        iSect = Visio.VisSectionIndices.visSectionUser
        If shp.SectionExists(iSect, Visio.VisExistsFlags.visExistsAnywhere) = 0 Then
            shp.AddSection iSect
        End If
        If shp.CellExists("User.UpdateFillsTrigger", Visio.visExistsAnywhere) = 0 Then
            iRow = shp.AddNamedRow(iSect, "UpdateFillsTrigger", 0)
            shp.Cells("User.UpdateFillsTrigger").FormulaU = _
                "=DEPENDSON(FillForegnd,FillBkgnd,FillPattern,ThePage!" & _
                actionUpdateCell & ".Checked) + " & _
                "CALLTHIS(""UpdateFills"",""bVisualUtilities"")"
        End If
        iSect = Visio.VisSectionIndices.visSectionProp
        If shp.CellExists(fillForegndCell, Visio.visExistsAnywhere) = 0 Then
            iRow = shp.AddNamedRow(iSect, Split(fillForegndCell, ".")(1), 0)
            shp.CellsSRC(iSect, iRow, Visio.VisCellIndices.visCustPropsLabel).FormulaU = _
                "=""Foreground"""
            shp.CellsSRC(iSect, iRow, Visio.VisCellIndices.visCustPropsType).FormulaU = _
                "=0"
        End If
        If shp.CellExists(fillBkgndCell, Visio.visExistsAnywhere) = 0 Then
            iRow = shp.AddNamedRow(iSect, Split(fillBkgndCell, ".")(1), 0)
            shp.CellsSRC(iSect, iRow, Visio.VisCellIndices.visCustPropsLabel).FormulaU = _
                "=""Background"""
            shp.CellsSRC(iSect, iRow, Visio.VisCellIndices.visCustPropsType).FormulaU = _
                "=0"
        End If
        If shp.CellExists(fillPatternCell, Visio.visExistsAnywhere) = 0 Then
            iRow = shp.AddNamedRow(iSect, Split(fillPatternCell, ".")(1), 0)
            shp.CellsSRC(iSect, iRow, Visio.VisCellIndices.visCustPropsLabel).FormulaU = _
                "=""Pattern"""
            shp.CellsSRC(iSect, iRow, Visio.VisCellIndices.visCustPropsType).FormulaU = _
                "=0"
        End If
        UpdateFills shp
    Next
End Sub

Finally, I added the UpdateFills() method that actually updates the Shape Data in the shapes whenever the FillForegnd, FillPattern or FillBkgnd values are changed.

Public Sub UpdateFills(ByVal shp As Visio.Shape)
Dim iSect As Integer
Dim iRow As Integer
Dim pag As Visio.Shape
    If Not shp.ContainingMaster Is Nothing Then
        Set pag = shp.ContainingMaster.PageSheet
    ElseIf Not shp.ContainingPage Is Nothing Then
        Set pag = shp.ContainingPage.PageSheet
    End If
    If pag Is Nothing Then
        Exit Sub
    End If
    iSect = Visio.VisSectionIndices.visSectionProp
    If UCase(Left(fillForegndCell, 5)) = "PROP." Or UCase(Left(fillBkgndCell, 5)) = "PROP." Or _
        UCase(Left(fillPatternCell, 5)) = "PROP." Then
         If shp.SectionExists(iSect, Visio.VisExistsFlags.visExistsAnywhere) = 0 Then
            shp.AddSection iSect
        End If
    Else
        Exit Sub
    End If
    If shp.CellExists(fillForegndCell, Visio.visExistsAnywhere) Then
        shp.Cells(fillForegndCell).FormulaU = "=""" & shp.Cells("FillForegnd").ResultStr("") & """"
    End If
    If shp.CellExists(fillBkgndCell, Visio.visExistsAnywhere) Then
        shp.Cells(fillBkgndCell).FormulaU = "=""" & shp.Cells("FillBkgnd").ResultStr("") & """"
    End If
    If shp.CellExists(fillPatternCell, Visio.visExistsAnywhere) Then
        shp.Cells(fillPatternCell).FormulaU = "=""" & Replace(shp.Cells("FillPattern").FormulaU, """", """""") & """"
    End If
End Sub

You can download the stencil that contains the VBA code here : http://bit.ly/cJYwdP

So, to use this, just Run the AddUpdateFillsTrigger macro whilst your desired shapes are selected.

image

This macro will three Shape Data rows to the selected shapes, which will display the RGB values of the Foreground and Background, plus the formula of the Pattern.

image

It is then a simple matter of using Data Graphics, as I showed in the earlier blog article, or Insert Field, as shown below, to display the Shape Data row values in the shape (don’t forget that you can enter text, field values and multiple rows in a text block):

image

Once this has been done to a ew shapes, then you easily use the built-in Visio reporting tool to list the shapes and their fills:

image

Not long now to the release of Visio 2010, but all of the code in this blog will work on any version and edition that I can think of.

Related

Filed Under: Color, Data Graphics, ShapeSheet Formulas, VBA, 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

Comments

  1. YossiD says

    February 4, 2016 at 6:06 am

    Thanks for these macros. I am creating a standard color pallet for block diagrams and wanted to display the RGB values in each shape without entering them manually. Your Custom Properties>Foreground field does the job nicely, except …

    For colors from the Visio standard color pallet, the Foreground field displays the color’s number rather than its RGB values, e.g. 2 vs. 255,0,0 for red. Is there any way to force the Foreground field to always display the RGB values?

    Reply
    • davidjpp says

      February 5, 2016 at 11:17 am

      I have put my answer in a new post :

      Reply

Trackbacks

  1. Displaying the Fill and Line Section Values of a shape | bVisual - for people interested in Microsoft Visio says:
    February 5, 2016 at 11:17 am

    […] few years ago, I wrote an article about displaying the RGB value of shapes ( see http://blog.bvisual.net/2010/04/22/displaying-the-rgb-values-of-shapes ). I had forgotten about it, but a reader recently asked if it was possible to force the Foregnd […]

    Reply

Leave a Reply Cancel reply

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

Primary Sidebar

  • LinkedIn
  • Twitter

Recent Posts

  • 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
  • Grid Snapping Revisited

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

  • 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
  • Grid Snapping Revisited

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