Visio Guy

Visio Discussions => Programming & Code => Topic started by: alexiscg on March 18, 2021, 06:15:29 PM

Title: Passing arguments from Visio Shapesheet to procedure in VBA not working
Post by: alexiscg on March 18, 2021, 06:15:29 PM
I have been working with Visio VBA for a couple of years and I constantly pass arguments from the ShapeSheet of a shape to several procedures in VBA using either RUNMACRO() or CALLTHIS() Functions. I either pass pass plain strings or the value of different formulas in the ShapeSheet. The most common argument that I pass to my procedures is the ID() of the shape. The issue that I am facing is that for some reason after I received a patch update of windows: https://support.microsoft.com/en-us/topic/march-15-2021-kb5001566-os-build-18363-1441-out-of-band-23c4c824-8638-43e9-a381-ff58213ae6fe , I am no longer able to pass arguments from the ShapeSheet of a Shape to my procedures in VBA. Whenever I use RUNMACRO or CALLTHIS, all the arguments that I pass, even if they are plain strings, in my procedure side everything that I get is "", blank information. Is there a way to know if this is just a bug or if this something that on purpose is staying in Visio VBA, maybe as a security measure. Must of my procedures are based on passing arguments from the ShapeSheet Shape to my VBA procedures and this issue is definitely putting me in a really bad spot, I was hoping that someone can help me with this.
Here is a simple example procedure:

Public Function HelloWorld(Number As Integer)
   
    If Number = 1 Then
   
      MsgBox ("Hello World 1")
   
    End If
   
    If Number = 2 Then
   
      MsgBox ("Hello World 2")
   
    End If
   

End Function
And this procedure is called in the EventDblClick of a Shape:

RUNMACRO("HelloWorld(1)","Test")
When the EventDblClick is triggered the value of Number stays as null, ignoring completly the argument sent in the RUNMACRO function, which is a 1. Since the argument of Number in the HelloWorld() function is not optional, it triggers an "Argument not optional" Compile error message.
Title: Re: Passing arguments from Visio Shapesheet to procedure in VBA not working
Post by: Visisthebest on March 18, 2021, 06:44:19 PM
I don't use arguments (yet) with CALLTHIS() but interesting to know if this issue is replicated, certainly a Windows patch should not cause such changes in behavior hopefully something else is causing this.
Title: Re: Passing arguments from Visio Shapesheet to procedure in VBA not working
Post by: Surrogate on March 18, 2021, 06:45:35 PM
Quote from: Visisthebest on February 24, 2021, 09:19:19 AM
I use CALLTHIS a lot, so good to see this explanation and example of using CALLTHIS:
https://bvisual.net/2021/02/22/using-the-callthis-function-in-visio/
sub-routine which fired by callthis function must have shape related argument!
Quote from: Surrogate on January 10, 2021, 01:15:58 PM
Sub-routine which call via CALLTHIS must have parameters
(https://visio.getbb.ru/gallery/image.php?pic_id=46)

from Visio 2002 Developer's Survival Pack (by Graham Wideman) (http://books.google.ru/books?id=8q5RG2CwF5wC&lpg=PP1&hl=ru&pg=PA232#v=onepage&q&f=false)
Title: Re: Passing arguments from Visio Shapesheet to procedure in VBA not working
Post by: Visisthebest on March 18, 2021, 07:08:15 PM
Yes Surrogate but you don't need to add the shape as an argument in an Action cell, you always get the shape calling the sub as an argument. I don't use any additional arguments that I add explicitly (yet).