Change Fill and Text Color Programmatically

Started by DinoCobolMan, August 22, 2014, 02:25:12 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DinoCobolMan

I am very new to VBA for Visio 2010. 

First Plea For Help
I have a group of shapes on a page from the Basic Shapes stencil. None of the shapes are connected with lines or grouped together.
I would like to change the fill color of all the Squares to be red. Below is the sample code that I tried.

Sub FillSquareRed()
  Dim shp As Visio.Shape
  Dim i As Integer
  ActiveWindow.DeselectAll
  For i = ActivePage.Shapes.Count To 1 Step -1
     Set shp = ActivePage.Shapes.ItemU(i)
       If Not (shp.Master Is Nothing) Then
           If shp.Master.Name = "Square" Then
  '             FillForegnd = RGB(255, 0, 0)
  '             shp.FillStyle = 3
  '             Set shp.FillStyle = RGB(255, 0, 0)
  '             shp("Fillforegnd").Formula = "RGB(255,  0,  0)"
  '            shp.Fillforegnd = RGB(255, 0, 0)
           End If
    End If
Next i
End Sub

Second Plea for Help
If a Square contains text, I would like to change the color of the text to blue. 
I don't really know where to get started on this code.    :-[

Sub ChangeTextBlue()
  Dim shp As Visio.Shape
  Dim i As Integer
  ActiveWindow.DeselectAll
  For i = ActivePage.Shapes.Count To 1 Step -1
     Set shp = ActivePage.Shapes.ItemU(i)
       If Not (shp.Master Is Nothing) Then
           If shp.Master.Name = "Square" Then

                CHANGE TEXT INSIDE SQUARE TO BLUE

           End If
    End If
Next i
End Sub




Surrogate

#1
Please try SHP.CellsSRC(visSectionCharacter, 0, visCharacterColor).FormulaU = 4

Visio Guy

You can access cells by name, like this:


shp.CellsU("FillForegnd").FormulaForceU = "RGB(255,0,0)"
shp.Cells("Char.Size").FormulaForce = "4pt"


The "U" is for universal names. Some cells can have two names, such as user- or shape data cells, or if cells appear as localized as (they once did?) in German and French Visio. For fixed cells that are always there, I use CellsU. For variable rows like user, shape data, controls, connection points, I use Cells.

FormulaU vs. Formula means "universal" syntax, which is essentially U.S. formatting: dots for decimals, commas for separating lists and function arguments.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

DinoCobolMan

VISIO GUY IS WORLD CLASS FORUM

I have been an IBM mainframe programmer for 34 years, and I mostly work in COBOL and JCL.  I am not new to VISIO drawings,  but I am very new to VBA programming.   I really appreciate all the outpouring of help form the Visio Guy site.  I actually received a response from the actual Visio Guy.

I have spent my whole weekend writing code and trying out all the different changes that I can make at the shape level.   

Thank you Visio Guy, Surrogate and all members of Visio Guy.  :)
DinoCobolMan       

wapperdude

One technique that is helpful in learning VBA is the macro recorder.  While it does add extra stuff, it does give you a good idea of where to begin.  It is quite helpful to have both the Visio window open and the VBE window open, side by side, before you execute the Recorder.  Then, start the Recorder, your first step will cause the VBE Project window to have a Module > NewMacros.  Dbl click the NewMacros, and the code window will show the macro.  Return to the drawing window, and then do your steps.  The code window will populate as you proceed.  Stop the macro when finished.

HTH
Wapperdude
Visio 2019 Pro

daihashi

Quote from: DinoCobolMan on August 24, 2014, 07:44:34 PM
VISIO GUY IS WORLD CLASS FORUM   

Agreed... stick around and you won't help but to learn by osmosis. Visguy, Yacine, June, jumpy, and many others are fantastic mentors... and they simply ooze pure knowledge and expertise. I learned on my own for the first 3 months, but after I came here my abilities really took off. More than anything, whenever I get their input... the most valuable thing that I get is that they help me look at the problem I am facing in a different way.