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?
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 ?
0
ProfessorJimJamCommented:
perhaps something like the attached one.
EE.xlsm
0

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?
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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 )
0
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi Andy. Thanks for spotting that and CodeCruiser that unfortunately doesn't work
0
ProfessorJimJamCommented:
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

0
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 ? )
0
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
0
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
0
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.