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

   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

Open in new window

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
Is the chart (sheet, workbook) opened or locked as readonly ?
ProfessorJimJamMicrosoft Excel ExpertCommented:
perhaps something like the attached one.
EE.xlsm

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CodeCruiserCommented:
Does changing

.Color = RGB(234, 122, 17) 'ERROR

to

.ForeColor.RGB = RGB(234, 122, 17)

work?
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

AndyAinscowFreelance programmer / ConsultantCommented:
Just noticed something - you talk of modifying the chart BUT use this code which is the sheet not the chart:
        Dim oFill As Excel.FillFormat
        oFill = Globals.ThisAddIn.Application.ActiveSheet.Fill

Open in new window

Should it not be something like this instead:
oFill = Globals.ThisAddIn.Application.ActiveSheet.ActiveChart.Fill
(or another possibility:  oFill = Globals.ThisAddIn.Application.ActiveSheet.Shapes(1).Fill )
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi Andy. Thanks for spotting that and CodeCruiser that unfortunately doesn't work
ProfessorJimJamMicrosoft Excel ExpertCommented:
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

Open in new window

AndyAinscowFreelance programmer / ConsultantCommented:
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 ? )
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi
I think the main issue is that this is VB.net not VBA. The code works in VBA but not VB.net
excelismagicCommented:
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
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.