Color Palette

  • Thread starter James Price at Premier
  • Start date
J

James Price at Premier

Is it possible using Viz 2007 VBA to programically allow a user to select a
colour from the colour palette?
 
C

Chris Roth [Visio MVP]

Hi James,

There are colors built in to each document, ie:

thisdocument.Colors

There is also a PaletteEntry member that matches Windows PALETTEENTRY
data structures. This might be of help too:

thisdocument.Colors.Item(1).PaletteEntry

NOt sure exactly what you want to do?

--
Hope this helps,

Chris Roth
Visio MVP


Visio Guy: Smart Graphics for Visual People

Articles: http://www.visguy.com
Shapes: http://www.visguy.com/shapes
Dev: http://www.visguy.com/category/development/
Forum: http://www.viguy.com/vgforum
 
J

James Price at Premier

Chris

I want to allow the user to customise their environment (in this case
changing colours in the background page), but I don't want them to go into
the background page to do so.

Ideally I would like to programatically allow them to select a colour from a
colour palette then update the shapes on the background page.

Does this help and is it possible?

Cheers

James
 
J

John Goldsmith_Visio_MVP

Hi James,

I looked at some similar functionality a while ago and at the time wasn't
able to raise the straight colors menu in a dialog (as per the Formatting
toolbar). In the end I dropped a temporary shape on the page (ensuring it
was selected) before calling the Fill dialog
(Application.DoCmds(visCmdFormatFill)). You can then read the resulting
color and formatting to your target shapes. Note that if you use this
approach you'll have to handle the errors that are raised when the OK or
Cancel buttons are clicked with no changes made (-2032466955) or with
changes (0 and 20).

Not sure if the standard toolbar fill is a general Office menu, but I'd be
interested in anybody else's approach.

Hope that helps.

Best regards

John


John Goldsmith (Visio MVP)
www.visualSignals.typepad.co.uk
www.visualSignals.co.uk
 
J

James Price at Premier

Thanks John. However I'm being a bit thick. If I have my selected shape how
can I run your line of code. ie activewindow.selection(1) ... then what?

Cheers

James
 
J

John Goldsmith_Visio_MVP

Hello James,

Here's a quick snippet that just shows the fill dialog and assigns to the
selected shape:

Sub SetFormat()

Dim shp As Shape

Set shp = ActiveWindow.Selection.PrimaryItem
If Not shp Is Nothing Then

On Error GoTo ErrorHandler
Application.DoCmd (visCmdFormatFill)
End If

ErrorHandler:
Select Case Err.Number
Case -2032466955
'OK or Cancel button clicked with no changes
'made to dialog OR changes made to dialog
'but Cancel clicked - Result, no changes to be applied
'Debug.Print Err.Number
shpDupe.Delete
Exit Sub
Case 0, 20
'Errors occur on any OK or Cancel button click
'(Error 20 - Description "Resume without error")
'Debug.Print Err.Number, Err.Description, Err.Source
Resume Next
Case Else
Debug.Print Err.Number, Err.Description, Err.Source
Resume Next
End Select

End Sub

If you're wanting to apply the formating to another shape/s on a different
page then my suggestion is that you drop a temporary shape call the dialog
as above and then copy what formatting you're after from your temporary
shape to your target shape. That way you can handle the user cancelling the
operation or apply 'inappropriate' choices etc. Not a perfect solution but
it does work.

Best regards

John


John Goldsmith (Visio MVP)
www.visualSignals.typepad.co.uk
www.visualSignals.co.uk
 
J

James Price at Premier

Thanks for that John. I was being a bozo and forgot to select the shape.
I'm sure I can create a temp shape, get the user to select a colour, capture
the fillforegnd colour and place it on the background page shape.

BTW - next time you are in London do you want to meet up for a coffee. Dave
P keeps mentioning you and I can't believe we haven't met before. My email
is (e-mail address removed)

Have a good weekend

James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top