Customized report colors "snapping" to windows default colors - vba

I have a chart in an Access 2010 report for which I am trying to set colors of different series dynamically. The user can use checkboxes to select series to chart, with the intent being that the series on the chart will take its color from the BackColor property of the checkbox's label.
The problem is that when I run my code to create the report, the colors used are not the ones on the corresponding labels. Instead it looks like they are "snapping" to the list of colors at the following link, referred to as "standard windows colours". List of standard windows colors in RGB and Long
For example:
With myChart.SeriesCollection(1)
.Interior.Color = RGB(195, 215, 155)
End With
Sets series 1 to a dark grey color, and debug.print myChart.SeriesCollection(1).Interior.Color returns 12632256, rather than 10213315 like it should. (Long color = Red + Green*256 + Blue*65536)
I have tried opening the chart object and defining the custom colors that I want to see on the palette for the chart, and setting the appropriate colors for the series manually. This works until I try to programatically change anything, at which point, all of the colors snap to the list I linked above.
Any ideas for how to dynamically set chart colors to custom values?

Managed to answer my own question. Manually customizing the palette in MS Graph was necessary, but from there, I need to reference the colors by their index on the palette (using .Interior.ColorIndex), rather than from their RGB or Long code. The index numbers for the palette are not in any logical order, but can be found in a file accessible from this site.
It's not quite as dynamic as I had hoped for, but this is definitely good enough for what I need to do.

Related

Coreldraw Multiple Contours in VBA

Guys I Am trying to set up a three colour text that is editable
Basically what I want is the text to be black
A 1st contour of 1mm that is white
a 2nd contour of 2mm thick which is black
I have tried the following 2 step contour
ActiveSelection.CreateContour cdrContourOutside, 2, 2, , , CreateRGBColor(0, 0, 0), CreateRGBColor(255, 255, 255)
this works perfectly as I want and when I edit the text the contour changes to the new text however the contours are both the same width (2mm) and not 1 & 2mm as i want
Also I cant get it to specify the correct color for each contour
If I break apart the 1st contour then add another this gives me contours of different widths and colors but I then loose the edit ability as the contour is not attached to the text
Any Ideas I Know its possible as I have seen a commercial macro that does it
Any Help appreciated
Mark
The best I can do for you is to show you the object model. I do not have CorelDraw and therefore cannot test anything.
Here is the link to the CorelDraw Object Model.
http://apps.corel.com/partners_developers/csp/resources/CorelDRAW%20VBA%20Object%20Model.pdf
And here is a link to a Programming Guide for CorelDraw.
http://apps.corel.com/partners_developers/csp/resources/dvba_pg.pdf
You can look up "Applying Effects" on page 72 of the programming guide which may help.
I would suggest also looking at creating curves from the .Shapes object and then looking at the TextRange object. the TextRange.Text property is the actual text you want to see and the TextRange.colorindex is the color of the text I believe. You will have to do some exploring, but this should help.

Excel VBA : Use the color of a shape in an If/Then case

I have created a chart on Excel using macros. Each of the shapes on the chart is filled with a color according to its category. I was wondering if it is possible to use the color of the shapes in an If/Then case to perform different actions, such as displaying the shapes with specific colors only.
For example, something similar to:
If shape.Fill.ForeColor.SchemeColor = 1 Then
shape.delete
I have tried that, but it doesn't seem to do anything to my chart. Does anyone have an idea of how to do it?
Thank you !!
Did you try checking the color with the corresponding RGB value? Since SchemeColor depends on the current color scheme it might be looking for a different color than you'd expect

How to change data label width in an Excel chart with VBA?

I want to change a label width in Excel chart by VBA code:
set lbl = SERIES1. points(1).datalabel
msgbox lbl.width 'this is working
lbl.width = 40 ' compile error: wrong number of arguments or invalid property assignment
I can get the label width but cannot change it. What am I doing wrong?
AFAIK, the width of a chart data point label is not configurable. Even though the width can be retrieved with VBA, it's not possible to set or change it with a VBA command or property.
According to the documentation, the DataLabels.Width property is read only.
Returns the width, in points, of the object. Read-only.
Source
Excel chart labels remain stubbornly uncooperative and resist formatting attempts, be it with VBA or with the UI.
That's (unfortunately) just how Excel works.
Don't shoot the messenger.
If you want to make a difference, consider raising an idea at excel.uservoice.com
This works in Excel 2016, you'll just need to adjust the series collection and point numbers to fit your needs. ActiveChart.FullSeriesCollection(1).Points(1).DataLabel.Width = 363.314.

Excel userform label different color text

I am creating a userform in Excel, I have a Label with a large amount of text in. I need to have certain words in Bold and in Red color and the rest in standard black.
I can change the whole text color in the properties but not just certain words.
Is this possible and if so how would I do it?
Select certain word and fill with BOLD or make it RED
Also this depends on your Excel Version, I using Excel 2013
I do believe that it isn't possible..
You'll have to create different Labels in order to change only certain parts of your text color.

Reinstate Excel chart default resizing behaviour using VBA

I am looking for a way to reinstate the default/native resizing behaviour of a chart in Excel 2010 once it has been disabled (e.g. by manipulating the chart with VBA).
Now I haven't been able to find anything anywhere about the behaviour I have in mind, so I am going to assume that it needs detailed explanation.
Input and select random numerical data into 4-5 cells in Excel, and insert a new Clustered Columns chart. You need to see a the chart's plot area. Now select the chart, and get the PlotArea.Top value with the following line
ActiveChart.PlotArea.Top
If you haven't touched the chart, this should return a value of 7. Now use one of the chart's handlebars to resize the chart vertically, and use the same command line again.
activechart.plotarea.top
Notice how the value returned is still 7. Now set this property to 7 in VBA.
ActiveChart.PlotArea.Top = 7
Again, grab one of the handlebars, resize the chart vertically and get the .top property again using:
ActiveChart.PlotArea.Top
Notice how the value has now changed. It will be either smaller or greater than 7 depending on whetehr you decreased or increased the size of the chart.
Once any element of a chart has been moved either manually or with VBA code, it loses this "absolute position" property and begins moving inside the ChartArea whenever the chart is resized. While some elements can be reset using .SetElement, this does not work for the Plot Area. For example, the following command lines do not reinstate the behaviour I am describing.
ActiveChart.SetElement msoElementPlotAreaNone
ActiveChart.SetElement msoElementPlotAreaShow
I do a lot of automated resizing of charts with VBA, and having the plot area move around by itself makes it a lot harder to predict the effect of resizing the chart and leads to inconstant results.
So back to the question: does anyone know of a way to reinstate this default behaviour, either for the entire chart, or at least specifically for the PlotArea?
Thanks in advance to anyone who may help!
Vincent
I ran into this when I manually resized the plot area and then when the legend is moved it did not resize the plot area at all.
I had tried to save my chart as a template (right click save as template in Excel 2013) but this still had the plot area manually set.
Therefore I would recommend keeping the auto-size behavior before saving a template, since the only way I know to re-set the chart auto-sizing behavior after it has been manually modified is to use a macro
Here is the macro I used to reinstate the auto-sizing behavior
Sub Macro1()
'
' this selects the chart based on the chart name
ActiveSheet.ChartObjects("Chart 4").Activate
' this selects the plot area
ActiveChart.PlotArea.Select
' this clears any custom formatting such as borders or fill colors
ActiveChart.PlotArea.ClearFormats
' this resets the auto-sizing behavior after plot area manually re-sized
ActiveChart.PlotArea.Position = xlChartElementPositionAutomatic
End Sub
References
Why plot area does not expand after clearing series legend?
Excel Chart Plot Area Auto Size - ExcelBanter