Add shapes and change their color at the same time through VBA


    Sponsored Links


  • 1. How to create ShapeExist function?
    Hi everyone, My client created a lot of drawing files (more than 20000 files) programatically. Because of the errors in the codes there are many shapes that are referencing custom properties in the other shapes that does not exist. I need to fix this by scanning the shapes, checking if the shapes they are pointing exists, and delete the reference if they don't exist. I first tried to use CellExist for the referenced shapes, but I hit the error, because I was trying to access execute the CellExist for the shapes that don't exist. I am using I can tell that the shape, for example Sheet.X does not exist in the file? Thanks!
  • 2. Interfacing with Visio
    Hi, I have some 2D shapes in a propriety format that I would like to place into Visio using OLE automation. Was wondering if anybody had any examples of doing this? Thanks for your help. Wayne
  • 3. Hard coded? Reference in Template
    My Visio has a reference to a COM object that we use. Apparently the reference keeps the path to the COM object saved in the actually file. So when user A creates a new document from my visio template and saves it the exact path to the COM object is saved into the file. The problem occurs when user B attempts to open the visio document that User A saved. If the COM object is installed into a different directory then user A they get an error that the libary is Missing. Am I missing something? Is there a way to override this functionality or some way to programmatically to force the document to look up the location of the COM object when the document is opened? Thanks, Mike
  • 4. VB Code (Add-In) To Read UML Objects properties
    Hi, I am creating an Add-In to generate some Word documents from my Visio Diagrams, and now I need to read the Objects of a an UML Model Diagram, such as each class and her Attributes, operations (With parameters). Like the "Static Structure Report" from "UML Report" of Visio But the only way I found to read this information was from Shapes.Item (as I show at the ex.). But using this, everything come together: as in strMethods reads all methods "+Insert() : Boolean +Update() : Boolean +Delete() : Boolean +Select(in CdTest : Long = 0) : Object ", And with this, if the user choose to hide some information on the shape I can't get it. I wanna read the objects properties, each value separated, and for each value I read I could read his sub-values, as Method Parameters. Any Idea? I read some thing sayng that this objects are not exposed via the COM interface, is it true ???? ex: strClassName = shpObj.Shapes.Item(7).Text strProperties = shpObj.Shapes.Item(6).Text strMethods = shpObj.Shapes.Item(5).Text Thanks, Claiton
  • 5. Data for 'x'position and 'width'size out of an excel
    Does anyone have any idea how to generate code like 'Add-Ons' ' Data Import'. Whish to have this as macro-code in a button in the Grafic to consume data from an excel worksheet.

Add shapes and change their color at the same time through VBA

Postby consulttech2004 » Sat, 19 Jan 2008 05:24:09 GMT

I want to use the ShapeAdded event so that when I add a shape from an
electrical stencil, the shape turns red (or green, or blue, or
whatever) so that it stands out from the rest of my drawing.  Any
ideas on how to do this consistantly through VBA?  Thanks in advance.

(VISIO Newbie)

Re: Add shapes and change their color at the same time through VBA

Postby John Goldsmith » Sat, 19 Jan 2008 06:31:01 GMT

Hello David,

For events, checkout this link:

 http://www.**--****.com/ (office.10).aspx (DVS - 
Handling Visio Events)

For the change of fill colour, you can use the macro recorder (Tools / Macro 
/ Record new macro...) to record the code as you make the changes manually 
in the UI, which you can then integrate into you final solution.

Are you sure, by the way, that you can't achieve what you're after just 
using the ShapeSheet?  On what basis do you want the colour to change?

Best regards


John Goldsmith

Similar Threads:

1.Changing color of shape with VBA code...

I would like to change the color of a shape with VBA code.  How can this be 
done?  code examples?

In the long run i would like to be able to do this using data from a 
database, controlled by the VBA code.  Thanks!

2.Change color of shape

I'm aware about reports that the Visio 2003 .NET/C# SDK will be
released somewhere Q1-2004. However I'm hoping that somebody can give
me a hint beforehand how to achieve to change the color of a shape

I got it working to find the selected Visio shape. And I can change
the text, however I don't have the slightest idea how to change the
color of the shape.

Maybe through SetFormula() but I don't understand what the arguments

//this works:
this.selectedShape.Text = visio_term + " exists";

//but what is SRCStream and formulaArray?
this.selectedShape.SetFormulas(ref SRCStream, ref formulaArray, 0);

The documentation does not reveal more then

public abstract new System.Int16 SetFormulas ( System.Array
SRCStream , System.Array formulaArray , System.Int16 Flags )
Member of Microsoft.Office.Interop.Visio.IVShape

Any one has a clue?


3.Change fill color of shape through code

I have been making my own master shapes.  I note that I can change the
fill color of some master shapes through code using the following

Shape.FillStyle = "red"

Or whatever I have defined my style to be.  It works pretty well for
our purposes.  The problem is that some master shapes don't seem to
have a fill color, and some that I have drawn (all of them, in fact)
don't seem to want to change color through VBA no matter what I do.
Is there something I'm missing?  Thanks in advance,


4.Change shape background color on a visio stencil


does somebody know how to change the background color of a shape already 
inserted to a stencil?

The problem is that I have to use a transparent image. When I drop it to the 
stencil, the background is transparent and the image quality is really bad 
(unrecognizable). If the background color of the image is white, the icon has 
a good quality and is recognizable.

Thanks, udo

5.How to Change Color of a Group of Shapes

Hi, Gurus,

I have a Visio program.   I created a group of line shapes.  I want to 
change the colors of all lines when a specific data goes beyond the range, 
say, if value > 1000.  How can I do that by using the group properties with 

Thanks so much in advance.


6. How to change Visio Shape color with vb???

7. Excel VBA - Add Sheet Change Event at Run Time

8. change font color of tasks or color of bars from VBA

Return to VISIO


Who is online

Users browsing this forum: No registered users and 24 guest