[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1441
  • Last Modified:

Color By Value Arguments in Visio 2003 VBA

I would like to add some code to color my org chart base on the value in the Status field.  I can do it manually using the Color By Values addon, but I would like to automate it.

Dim objapp As Visio.Application
Dim objaddon As Addon

    Set objapp = Visio.Application
    Set objaddon = objapp.Addons.Item("Color By Values") 'Refreshes database from Visio
    objaddon.Run ("/color = Status") '****This is the part where I need the arguments****

Any help would be appreciated.
  • 2
1 Solution
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
I ann't find any documentation about this add-in that lists the commands. I've sent a query to a number of long-time Visio experts and will let you know if I hear anything useful.

bnielsen56Author Commented:
Thanks for checking.  I ended up adding a color loolup table to the linked database that translates the status of each position to a color, such as Vacant = 0 (visYellow) and Filled = 1 (visWhite).  Then I loop through the pages and shapes to apply the colors.  This is run when the visio document is opened, saved, or closed.
Sub ColorShapes()

Dim shpObj As Visio.Shape
Dim i As Integer
Dim clr As String
Dim docObj As Document
Dim pagsObj As Pages
Dim curPageIndx As Integer
Dim PagObj As Page
Set docObj = ThisDocument
Set pagsObj = docObj.Pages

For curPageIndx = 1 To pagsObj.Count ' iterate through the collection of pages
    Set PagObj = pagsObj.Item(curPageIndx) ' retrieve the page object at the current index
    If PagObj.Background = False Then ' Ignore if the current page is a background page
    ActiveWindow.Page = PagObj
        For i = 1 To ActivePage.Shapes.Count
            Set shpObj = ActivePage.Shapes(i)
                If shpObj.CellExists("Prop.Color", 0) Then 'Check if color cell exists in shape
                    clr = shpObj.Cells("Prop.color").ResultStr(0) 'Set color variable to color number
                    shpObj.Cells("FillForegnd").Formula = clr 'Set shape fill color to color from database
                End If
    End If
Next curPageIndx
End Sub

Open in new window

Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
Thanks for posting the solution you developed. I've conversed with several Visio experts but so far, all I've found out is that the 'color by values' add-in is either undocumented or was documented so long ago that nobody knows where the documentation is!

If I ever track it down, I will post it here in case is helps anyone else.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now