• 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➡
      • 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 / Shape Design / ShapeSheet Formulas / Using the CALLTHIS function in Visio

Published on February 22, 2021 by David Parker

Using the CALLTHIS function in Visio

Visio was the first non-Microsoft application to include VBA within it back in the mid-nineties. All of the desktop Microsoft Office applications currently include VBA, although Microsoft have been rumoured to want to replace it for many years, and now there is an alternative scripting option becoming available that is suitable for the web too.

Visio was acquired by Microsoft in 2000, and there are still many scenarios when it is useful to have VBA procedures available in Visio for the Desktop. These procedures can be created using the recorder, and then edited, or just created manually. Every Visio document can contain a VBA project, but it must be saved with the .vsdm extension for documents, .vssm extension for stencils, or .vstm extension for templates. The last letter, m, informs Windows that this file could contain macros, as opposed to the normal last letter x, which cannot. Even with this extension, users, or their IT department, may not enable the macros in Visio documents.

The CALLTHIS function in Visio can be used to run a procedure (sub-function) in a Visio Visual Basic document and pass through a reference to the shape that the function is called from. The Microsoft Docs provide an explanation of this useful technique, and it does describe some examples, but it does not show the VBA code that these examples need, nor does it show them working. It also does not make it clear that these procedures do not need to be in the Visio diagram document, but can be in a stencil that is open in the active Visio session. This is important because it means that VBA code can be centralised and distributed for use use on many other documents.

  • Using CALLTHIS with code in a document
  • Using CALLTHIS with code in a stencil
  • The VBA code behind

The shapes on the Visio document call code in the diagram document itself (CallThisExamples.vsdm), or in the stencil (CallThisExamples.vssm). They should be downloaded an placed into the same folder in OneDriveforBusiness. Opening the diagram document in Visio for the Desktop should then open the stencil in the workplace too.

VBA Code

The VBA code is duplicated in the document and in the stencil in order to demonstrate the how the procedures could be called from each.

ThisDocument is actually a Class, not a Module, and so needs to be included in the argument that is passed to the CALLTHIS function.

In Document

ThisDocument

Option Explicit

Public Sub A(vsoShape As Visio.Shape)
    MsgBox vsoShape.Name, _
        vbInformation, "ThisDocument.A"
End Sub

Public Sub B(vsoShape As Visio.Shape, arg1 As String)
    MsgBox vsoShape.Name & " with arg1=" & arg1, _
        vbInformation, "ThisDocument.B"
End Sub

Public Sub C(vsoShape As Visio.Shape, arg1 As String, arg2 As String)
    MsgBox vsoShape.Name & " with arg1=" & arg1 & ", arg2=" & arg2, _
        vbInformation, "ThisDocument.C"
End Sub

ModuleInDocument

Option Explicit

Public Sub p(vsoShape As Visio.Shape, heightInCm As String)
    MsgBox vsoShape.Name & " is " & heightInCm & " high", _
        vbInformation, "ModuleInDocument.p"
End Sub

Public Sub q(vsoShape As Visio.Shape, heightInCm As Double, widthInIU As Double)
    MsgBox vsoShape.Name & " is " & CStr(heightInCm) & " high by " & CStr(widthInIU) & " wide", _
        vbInformation, "ModuleInDocument.q"
End Sub

In Stencil

ThisDocument

Option Explicit

Public Sub A(vsoShape As Visio.Shape)
    MsgBox vsoShape.Name, _
        vbInformation, "CallThisExamples.ThisDocument.A"
End Sub

Public Sub B(vsoShape As Visio.Shape, arg1 As String)
    MsgBox vsoShape.Name & " with arg1=" & arg1, _
        vbInformation, "CallThisExamples.ThisDocument.B"
End Sub

Public Sub C(vsoShape As Visio.Shape, arg1 As String, arg2 As String)
    MsgBox vsoShape.Name & " with arg1=" & arg1 & ", arg2=" & arg2, _
        vbInformation, "CallThisExamples.ThisDocument.C"
End Sub

ModuleInStencil

Option Explicit

Public Sub p(vsoShape As Visio.Shape, heightInCm As String)
    MsgBox vsoShape.Name & " is " & heightInCm & " high", _
        vbInformation, "CallThisExamples.ModuleInStencil.p"
End Sub

Public Sub q(vsoShape As Visio.Shape, heightInCm As Double, widthInIU As Double)
    MsgBox vsoShape.Name & " is " & CStr(heightInCm) & " high by " & CStr(widthInIU) & " wide", _
        vbInformation, "CallThisExamples.ModuleInStencil.q"
End Sub

My new book on Visualizing Processes with Microsoft Visio has launched

Back in the early 1990s, there was an application called ABC Flowcharter that was the market leader for diagramming business flowcharts, but some of the brains behind Aldus PageMaker saw an opportunity to create something smarter, and left to write the Visio product, with the stated aim to overtake ABC Flowcharter within 2 years. They…

Interactive Demographics of the European Union in Visio

I was recently contacted by a reader, Stanley M. Max (Towson University lecturer), who had started creating a Visio map of the 27 countries in the European Union in 2020, along with the demographics culled from Wikipedia. He wanted to know if the map and stats could be combined to make a more appealing presentation.…

Understanding Visio Data Graphic’s Color by Value

The desktop Visio editions, Visio Professional and Visio Plan 2, have a great way of automatically displaying data as Data Bars, Icon Sets, Text Callouts and Color by Value. The first three types of Data Graphics require sub-shapes to be inserted into each shape that they are applied to, but the last one, Color by…

Pushing Data Visualizer in Visio beyond its limits

My last post was about some of the lessons learnt when trying to push Data Visualizer to its limits, but this one has some ways of overcoming these limitations. The main lesson learnt is that DV binds the shapes within the DV container shape, CFF Data Visualizer, and controls some of the ShapeSheet cells that…

Pushing Data Visualizer in Visio to the limits!

Regular readers of my blog will know that I like to use the Data Visualizer (DV) in Visio Plan 2, but I recently tried to help a user who really decided to push it to the limits. In this scenario, there were multiple connections, but with different labels, being created between the same flowchart shapes,…

Setting Theme defaults in Visio

I was recently asked how to change the default font size and line weight in Visio, and then saw then many others are asking the same sort of question. I found one reasonable answer suggesting that you should create a new document from your required template, then edit the Styles to suit, and then save…

Related

Filed Under: ShapeSheet Formulas, Visio for Desktop Tagged With: ShapeSheet, 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

  • Counting glued and connected shapes in Visio
  • My new book on Visualizing Processes with Microsoft Visio has launched
  • Layer Set menu options and calls from code added to LayerManager
  • Interactive Demographics of the European Union in Visio
  • Understanding Visio Data Graphic’s Color by Value

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 Shape Data Shape Design ShapeSheet ShapeSheet Functions SharePoint 2013 SQL Teams Themes 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

  • LinkedIn
  • Twitter

Search this website

Recent posts

  • Counting glued and connected shapes in Visio
  • My new book on Visualizing Processes with Microsoft Visio has launched
  • Layer Set menu options and calls from code added to LayerManager
  • Interactive Demographics of the European Union in Visio
  • Understanding Visio Data Graphic’s Color by Value

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