• 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 / Visio 2013 / Making unused data-linked SharePoint columns in Visio invisible automatically

Published on March 26, 2015 by David Parker

Making unused data-linked SharePoint columns in Visio invisible automatically

I described how and why I sometimes link a SharePoint document library to Visio documents in a previous article ( see http://blog.bvisual.net/2015/02/10/displaying-sharepoint-document-library-column-values-on-visio-services-diagrams/). I mentioned that I always switch off the visibility of some columns because they are rarely needed in my Visio shapes as shape data rows. In this article, I present a VBA macro that can switch them off for you, therefore ensuring consistency.

The Link Data to Shapes feature in Visio does not allow for filtering of columns or rows when SharePoint lists are used as a data source. One answer is to create a view of the list in SharePoint to restrict the rows and some columns, but other columns still get pulled through to the External Data recordsets in Visio by default:

image

First, I created a constant in a VBA module which contains a semi-colon separated list of the columns that I want to hide:

Private Const mUnusedSPCols As String = "ID;Name;Keywords;Category;Content Type;File Size;App Created By;App Modified By;Workflow Instance ID;File Type;URL Path;Path;Item Type;Encoded Absolute URL"

Second, I wrote a function that returns the index of a column by Name (or DisplayName). This is necessary because I do not want an error that could be caused by returning the DataColumn for a name that does not exist.

Private Function getColumnIndexByName(ByVal drs As DataRecordset, _
    ByVal columnName As String) As Integer
Dim column As Integer
    getColumnIndexByName = -1
    For column = 1 To drs.DataColumns.Count
        If drs.DataColumns.Item(column).Name = columnName _
                Or drs.DataColumns.Item(column).DisplayName = columnName Then
            getColumnIndexByName = column
            Exit For
        End If
    Next column
End Function

Thirdly, I wrote the macro that loops through each of the column names in the mUnusedSPCols list and turns off their visibility.

Public Sub HideUnusedSPCols()
‘Get the datarecordset
Dim drs As DataRecordset
Dim drsExists As Boolean
Dim win As Visio.Window
    If Visio.ActiveDocument.DataRecordsets.Count = 0 Then
        Exit Sub
    End If
    Set win = Visio.ActiveWindow.Windows.ItemFromID(Visio.visWinIDExternalData)
    If drsExists = False Then
        Set drs = win.SelectedDataRecordset
    End If
    If drs Is Nothing Then
        ‘Abort if not present
        MsgBox "There is no active external data!", vbInformation
        Exit Sub
    End If
   
    If Len(mUnusedSPCols) = 0 Then Exit Sub
   
On Error GoTo errHandler
Dim i As Integer
Dim aryUnusedSPCols() As String
   
‘Enable diagram services
Dim DiagramServices As Integer
    DiagramServices = ActiveDocument.DiagramServicesEnabled
    ActiveDocument.DiagramServicesEnabled = visServiceVersion140 + visServiceVersion150

Dim UndoScopeID As Long
    UndoScopeID = Application.BeginUndoScope("Column Settings")
   
Dim vsoDataColumn As Visio.DataColumn
Dim colNumber As Long
Dim colName As String

    aryUnusedSPCols = Split(mUnusedSPCols, ";")
    For i = 0 To UBound(aryUnusedSPCols)
        colName = aryUnusedSPCols(i)
        colNumber = getColumnIndexByName(drs, colName)
        If colNumber > -1 Then
            Set vsoDataColumn = drs.DataColumns(colNumber)
            vsoDataColumn.Visible = "FALSE"
        End If
    Next
   
exitHere:
    Application.EndUndoScope UndoScopeID, True

    ‘Restore diagram services
    ActiveDocument.DiagramServicesEnabled = DiagramServices
    Exit Sub
errHandler:
    MsgBox Err.Description
    Resume exitHere
End Sub

The result is that the visibility of these columns is switched off:

image

It saves me time and ensures consistency, so I thought I would share it.

Related

Filed Under: Visio 2013 Tagged With: SharePoint 2013, Visio Services

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

  • 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