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


    Sponsored Links


  • 1. CommandBarButton Picture Displays Improperly in 2007/B2
    My command bar pictures are displaying improperly in Visio 2007 when they were correct in Visio 2003 and Visio 2002. My C++ code is basically this: Office::_CommandBarButton* pCmdBarBtn = SomeCommandBarButton; PICTDESC PictDesc; PictDesc.cbSizeofstruct = sizeof(PictDesc); PictDesc.picType = PICTYPE_BITMAP; HICON hIcon = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(nIconResource), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); ICONINFO IconInfo; GetIconInfo(hIcon, &IconInfo); PictDesc.bmp.hbitmap = IconInfo.hbmColor; PictDesc.bmp.hpal = NULL; CComPtr<IPictureDisp> pColor; OleCreatePictureIndirect(&PictDesc, __uuidof(pColor), TRUE, (void**)&pColor); pCmdBarBtn->PutPicture(pColor); CComPtr<IPictureDisp> pMask; PictDesc.bmp.hbitmap = IconInfo.hbmMask; PictDesc.bmp.hpal = NULL; OleCreatePictureIndirect(&PictDesc, __uuidof(pMask), TRUE, (void**)&pMask); pCmdBarBtn->PutMask(pMask); The resources are RT_GROUP_ICON type and contain 16x16 16 color icons. Visio is attempting to render the icons because I can make out the basic shape but the coloring is incorrect. Am I doing something wrong or has a bug been introduced here? BTW my OS is XP Pro/SP2. Thanks.
  • 2. Referencing Page Names in a Custom Properties Dialog Box
    Hi, I created a report based on the elements of a page in a Visio document. However, I would like to be able to run this report in an empty page of the same document and reference the page name that this report should be based on. The reason for this being that some pages might be too long to fit a report as well as the contents. Also, I would like to avoid using any other application like Excel for exporting information. The way I tried to do this was by customizing the properties of the report object so that on drop it will ask what page to make reference to. My idea was to provide the name of all pages within the same document in a fixed list for easier selection. Then, on selecting a given page name, have the report reference that page and run the query it is supposed to run. However, I can't figure out how to pass the PAGENAME argument (if that is the one I should actually be using) to the report object. Basically, I have been unable to populate a fixed list with the names of all pages in the Visio document. If anyone knows the solution to this issue or have any ideas on how to make this happen, it will be greatly appreciated. Thanks.
  • 3. Change the application name with VBA
    Hello! Does somebody know how I can change the application name with VBA ??? Best regards Mario Wilding
  • 4. Script Question to Highlight
    Hello I've just recently got back in to using Visio, from when I first encountered it as Visio4. I have noticed that you can now use VBA to customise visio diagrams. Is it then possible to write script to which is executed, say via a button to perform some sort of action, say something like highlight a shape or some sort of connector? Kind Regards Ricky (Visio 2003)
  • 5. pasteing an excel cell into visio drawing
    Is there an easy way to link individual cells from and excell worksheet to a drawing in Visio so the data in Excel will be seen in Visio and be updated each time Excel is updated? I'm using the copy and paste special as a "Microsoft Excel Worksheet" but the data shown is not easily formatted. I need the information to be inside a retangle shape which can be adjusted without the font changing. Thanks

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