Murray Brown
asked on
VB.net Excel Add-in Property Color is ReadOnly
Hi
In my VB.net Excel Add-in I am trying to fill a chart with a two color gradient
I get the Error 'Propert Color is ReadOnly ' at the two lines marked error
In my VB.net Excel Add-in I am trying to fill a chart with a two color gradient
I get the Error 'Propert Color is ReadOnly ' at the two lines marked error
Sub oFill_Chart()
Dim cht As Object
cht = Globals.ThisAddIn.Application.ActiveChart.Parent
Dim oFill As Excel.FillFormat
oFill = Globals.ThisAddIn.Application.ActiveSheet.Fill
With oFill
.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal, 1)
With .GradientStops(1)
.Color = RGB(234, 122, 17) 'ERROR
.Position = 0
.Transparency = 0
End With
With .GradientStops(2)
.Color = RGB(55, 255, 122) 'ERROR
.Position = 1
.Transparency = 0
End With
.GradientStops.Insert(RGB:=RGB(128, 122, 201), Position:=0.5, Transparency:=0)
.Visible = Microsoft.Office.Core.MsoTriState.msoTrue
End With
End Sub
Is the chart (sheet, workbook) opened or locked as readonly ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Does changing
.Color = RGB(234, 122, 17) 'ERROR
to
.ForeColor.RGB = RGB(234, 122, 17)
work?
.Color = RGB(234, 122, 17) 'ERROR
to
.ForeColor.RGB = RGB(234, 122, 17)
work?
Just noticed something - you talk of modifying the chart BUT use this code which is the sheet not the chart:
oFill = Globals.ThisAddIn.Applicat ion.Active Sheet.Acti veChart.Fi ll
(or another possibility: oFill = Globals.ThisAddIn.Applicat ion.Active Sheet.Shap es(1).Fill )
Dim oFill As Excel.FillFormat
oFill = Globals.ThisAddIn.Application.ActiveSheet.Fill
Should it not be something like this instead:oFill = Globals.ThisAddIn.Applicat
(or another possibility: oFill = Globals.ThisAddIn.Applicat
ASKER
Hi Andy. Thanks for spotting that and CodeCruiser that unfortunately doesn't work
did you try
Sub test()
Dim oFill As FillFormat
Set oFill = ActiveSheet.Shapes(1).Fill
With oFill
.TwoColorGradient msoGradientHorizontal, 1
With .GradientStops(1)
.Color = RGB(234, 122, 17)
.Position = 0
.Transparency = 0
End With
With .GradientStops(2)
.Color = RGB(55, 255, 122)
.Position = 1
.Transparency = 0
End With
.GradientStops.Insert RGB:=RGB(128, 122, 201), Position:=0.5, Transparency:=0
.Visible = msoTrue
End With
End Sub
Back to my original posting:
Is the chart (sheet, workbook) opened or locked as readonly ?
( Instead of having that code in your add in what happens if you add a macro to the excel workbook directly and run the code in that ? )
Is the chart (sheet, workbook) opened or locked as readonly ?
( Instead of having that code in your add in what happens if you add a macro to the excel workbook directly and run the code in that ? )
ASKER
Hi
I think the main issue is that this is VB.net not VBA. The code works in VBA but not VB.net
I think the main issue is that this is VB.net not VBA. The code works in VBA but not VB.net
i am not very good with .net language
Here's an article that discusses migrating VBA to VB.NET:
http://msdn.microsoft.com/en-us/library/aa192490%28v=office.11%29.aspx
>> Non-compliant content removed.
>> kaufmed, Topic Advisor
Here's an article that discusses migrating VBA to VB.NET:
http://msdn.microsoft.com/en-us/library/aa192490%28v=office.11%29.aspx
>> Non-compliant content removed.
>> kaufmed, Topic Advisor
ASKER
Thanks