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


    Sponsored Links


  • 1. How to: SolutionXMLElement
    Hey All, I am trying to figure out or find a sample or determine if it is possible to use the 'SolutionXMLElement' method to add / read custom data added to a Visio document. While I've seen some discussions, I have not seen any tangible, working samples. For example, I would like to do something like the following: MyVisDoc.SolutionXMLElement("CustomXML") = "CustomValue" MsgBox MyVisDoc.SolutionXMLElement("CustomXML") Unfortunately, the above does not work. Can anyone provide a working sample or link to a working sample? Thanks, TC
  • 2. visCtrlTypeSPLITBUTTON in Toolbar
    Hi can someone tell me that how i used visCtrlTypeSPLITBUTTON_MRU_COMMAND to create toolar button like a pointer tool in Standard toolbar. if anybody know please give me a sample to do that. Please its urgent .
  • 3. How to check selected tool in the toolbar
    Hi can we know programatically whether user click the pointer tool button in standard toolbar or reactangle tool in the drawing toolbar. Thanks
  • 4. How to create thumbnail of .vsd file
    Hi is there any VISIO API by which we create thumbnail of a Visio drawing (.vsd file) , just like as the window explorer show s.
  • 5. MS Project Timeline - automate some of the formating
    I don't know if this is the right group but I need to start somewhere. Does anyone know how to customize a timeline that has been created as a result of importing MS project data? I've created a MS project timeline, imported it into Visio's timeline tool and it works. The issue is the timeline is a mess and in order to make it look acceptable I need to tweak it a lot. I'd like to find a way to automate some of the work. Can I do this and if I can where can I go to find an example or two? For example, I'd like to have the milestones alternate, top, bottom, top, etc. Right now they all come in on the bottom and the words are all jumbled together. I'd like to also change the color of the different section of the timeline based on the different phases of the project. If I could get those two things done the amount of tweaking would be a lot less. I hope this made sense? I have googled this but I have not found a lot of help based on the search criteria I've used. Thanks, rick

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 33 guest