Can't amend Data Graphics Fields in VBA

Started by TheSiMaN, February 01, 2021, 12:56:58 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TheSiMaN

Hi all,

I've done a lot of VBA in Excel and now need to do some work in Visio.

I've got a macro that creates a data connection and runs a query based on various things that it finds within the Visio. It then links the appropriate row with the appropriate shape. So far, so good.

The issue arises where it only shows the first columns of data in the data graphics field. When I start to record a macro, this box becomes greyed out so I can't amend it then view the code to see what its doing or the parameters I need to call on.

I've created a 'Master' shape in a stencil with the data graphic fields I want selected and in the format I want them. However, I can't seem to transfer this formatting over to the Shapes I've added data to.

Below is the code I've tried. The first line works to assign the data but the 2nd doesn't apply the Graphic Field selections that I need (this is part of a loop that goes through every shape in the Visio looking for keywords from the query and linking when it matches)

Am I barking up the wrong tree? There must be some way of choosing these fields - I have hundreds of Visio's that need to be updated every week so manually changing these fields isn't going to work.


                Application.ActiveDocument.Pages(Z).Shapes.ItemFromID(k).LinkToData nCount, lngRow, True ' Works to link the data
                Application.ActiveDocument.Pages(Z).Shapes.ItemFromID(k).DataGraphic = Application.Documents.Item("H:\My Documents\My Shapes\DataShape1.vssx").Masters.ItemU("Test1") ' doesn't work
     


Any help appreciated

Thanks




Paul Herber

I think your data graphic has to be a master that is already within the document masters.
You should then be able to set the graphic to :
Application.Document.Masters.ItemU("Test1")

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

TheSiMaN

Thanks for the quick response.

So I just need to copy in the master (programmatically) before I get to that bit of the code and reference it within the 'ActiveDocument' and it should work? I'll give it a go!


TheSiMaN

I'm now getting an error: 'Inappropriate target object for this action' when I use the following code:


Application.Documents.OpenEx "DataShape1.vssx", visOpenRO + visOpenDocked
...
Application.ActiveDocument.Pages(Z).Shapes.ItemFromID(k).DataGraphic = Application.Documents.Item("DataShape1.vssx").Masters.ItemU("Test1")



Any idea why? (the Master is literally a copy of this shape with the Data Graphic Fields that I want selected)