+ Reply to Thread
Results 1 to 3 of 3

How do I use VBA to change line colors

  1. #1
    Registered User
    Join Date
    06-02-2005
    Posts
    1

    How do I use VBA to change line colors

    I have a multi-series 2-D line chart. Each series is a different color, but these colors appear to be chosen automatically, and are not the colors I want to use.

    I've tried this:

    GraphObj.SeriesCollection(2).Interior.Color = RGB(255, 180, 0)

    But this generates the error "Unable to set the Color property of the Interior class."

    So, where in the depths of the object model can I go to change the color of the lines? And if you can tell me that, I'll bet you can also tell me where to go to change the width or thickness of a line, too.

    Any help is very much appreciated.

  2. #2
    Andy Pope
    Guest

    Re: How do I use VBA to change line colors

    Hi,

    For a line you would need,

    GraphObj.SeriesCollection(2).Border.Color = RGB(255, 180, 0)

    and for other formatting try these instead of Color.
    .Weight = xlMedium
    .LineStyle = xlContinuous

    Using the macro recorder is a good way of getting this syntax.

    You can change the automatic colours for charts. Use the menu Tools >
    Options. On the Color tab is a section for chart lines and fills.

    Cheers
    Andy

    Dilbert00 wrote:
    > I have a multi-series 2-D line chart. Each series is a different color,
    > but these colors appear to be chosen automatically, and are not the
    > colors I want to use.
    >
    > I've tried this:
    >
    > GraphObj.SeriesCollection(2).Interior.Color = RGB(255, 180, 0)
    >
    > But this generates the error "Unable to set the Color property of the
    > Interior class."
    >
    > So, where in the depths of the object model can I go to change the
    > color of the lines? And if you can tell me that, I'll bet you can also
    > tell me where to go to change the width or thickness of a line, too.
    >
    > Any help is very much appreciated.
    >
    >


    --

    Andy Pope, Microsoft MVP - Excel
    http://www.andypope.info

  3. #3
    Tushar Mehta
    Guest

    Re: How do I use VBA to change line colors

    In XL, turn on the macro recorder (Tools | Macro > Record new
    macro...), do whatever it is you want by hand, turn off the recorder,
    and switch to the VBE. In 99+% of the cases, XL will give you the
    necessary code, which you can then adapt to your own needs.

    --
    Regards,

    Tushar Mehta
    www.tushar-mehta.com
    Excel, PowerPoint, and VBA add-ins, tutorials
    Custom MS Office productivity solutions

    In article <[email protected]>,
    [email protected] says...
    >
    > I have a multi-series 2-D line chart. Each series is a different color,
    > but these colors appear to be chosen automatically, and are not the
    > colors I want to use.
    >
    > I've tried this:
    >
    > GraphObj.SeriesCollection(2).Interior.Color = RGB(255, 180, 0)
    >
    > But this generates the error "Unable to set the Color property of the
    > Interior class."
    >
    > So, where in the depths of the object model can I go to change the
    > color of the lines? And if you can tell me that, I'll bet you can also
    > tell me where to go to change the width or thickness of a line, too.
    >
    > Any help is very much appreciated.
    >
    >
    > --
    > Dilbert00
    > ------------------------------------------------------------------------
    > Dilbert00's Profile: http://www.excelforum.com/member.php...o&userid=23993
    > View this thread: http://www.excelforum.com/showthread...hreadid=376141
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1