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


    Sponsored Links


  • 1. Get document XML - 2
    Hi everyone, My query is whether it is possible to get the document XML programatically without saving it to a file. So, I am working on a document and through VBA code in the document I want to get the XML representation of the document. Basically, I want to save the file to memory instead of a file. Cheers! xargon
  • 2. Reference row by name
    Hi there, I'm trying to add a custom property to a number of document masters, however, I'm having trouble with the row reference (visRowProp). Can I reference it by name (ie "Temperament"), rather than by index? It seems to set the row name ok using sName, but then falls over when trying to reference it. (Note I've tried various combinations such as visRowProp & sName etc. etc. (no laughing please!)) Many thanks John Sub AddMasterProps() Dim mstr As Master For Each mstr In ActiveDocument.Masters Select Case mstr.Name Case "Dog" Case "Cat" Call AddCustPropRow(mstr) Case "Mouse" Case Else End Select End Sub Private Sub AddCustPropRow(ByRef mstr As Master) Dim sName As String Set sName = "Temperament" With mstr.Shapes.Item(1) .AddNamedRow visSectionProp, sName, 0 .CellsSRC(visSectionProp, visRowProp, visCustPropLabel).FormulaU = """Temperament""" .CellsSRC(visSectionProp, visRowProp, visCustPropValue).FormulaU = """BadTempered""" End With End Sub
  • 3. newbie: link custom property to a separate text field
    Hi all, I have a macro that creates a new document based on a template. The template has one background page and one foreground page, and a stencil. Once the new drawing has been created, I add a bunch of custom properties to the foreground page's PageSheet (values coming from a user form type wizard thing). I figure that custom properties are pretty versatile things and can be controlled by VBA pretty easily. I use the foreground page's PageSheet for the custom properties so that I can display it (the custom property window) as the user edits the foreground page. I want a particular custom property on the foreground page to control the text in a text field that's on the background page somehow, so that I can eventually lock the background, and the only way to change the text field's text is by changing the custom property. How can i control a text field on a background page from a custom property on the foreground page? Is this a really awkward way of doing this? Any suggestions or help would be great. Ben
  • 4. removing all keyboard accelerators programatically
    Hi everyone, I am trying to remove all keyboard accelerators programatically from the open Visio document. I tried a function like this but this does not seem to work :( Public Sub RemoveAccelerators() Dim uiObj As Visio.UIObject Dim accelTableObj As Visio.AccelTable Dim accelItemsObj As Visio.AccelItems Dim accelItemObj As Visio.AccelItem Dim i As Integer 'Retrieve the UIObject object for the copy of 'built-in menus. Set uiObj = Visio.Application.BuiltInMenus 'Set accelTableObj to the Drawing menu set. Set accelTableObj = uiObj.AccelTables.ItemAtID(visUIObjSetDrawing) 'Retrieve the accelerator items collection. Set accelItemsObj = accelTableObj.AccelItems 'Retrieve the accelerator item for the Visual Basic Editor by iterating 'through the accelerator items collection and locating the item you want to delete. For i = accelItemsObj.count - 1 To 0 Step -1 accelItemsObj.Item(i).Delete Next i 'Tell Visio to use the new custom menus while the document is active. ThisDocument.SetCustomMenus uiObj End Sub Can someone help me. I am wondering what I am doing wrong. if I search for a particular accelerator in the list and delete it, it works fine. However, deleting all the accelerators in the list seems to have no effect! Thanks and cheers! xargon
  • 5. Stop a stencil from being closed or edited
    Hi everyone, I would like to know if there is a way to stop the document stencil from being hidden, closed or edited manually. I would liek to do this from VBA code. the idea is basically to have the client work with a pre-defined collection of shapes and not have him change it during use (i.e. add, delete or rename a shape). Thanks and cheers! xargon

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