Results 1 to 4 of 4

Thread: [RESOLVED] How to select/copy a chart in a chart sheet

  1. #1

    Thread Starter
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Resolved [RESOLVED] How to select/copy a chart in a chart sheet

    Hello.

    I’ve been working on a project, and had fantastic success with the search feature the last few days – I was able to find answers for everything I was looking for (and I even gave good rep to the people that posted the answers I was looking for). But now I’m stuck, and I need a little help.

    I have an Excel file that I’m working with via .NET. One of the tabs is a chart – which I understand is actually a chart sheet (the entire tab is a big chart, with no cells).

    I can open the Excel file:

    Code:
    Dim xExcelApp As New Excel.Application
    xExcelApp.Workbooks.Open("C:\test.xls")
    My problem is with the chart sheet. I want to select the chart, and then copy it (so I can paste it somewhere else). No matter what I try, I can’t seem to select the chart in the chart sheet:

    Code:
    xExcelApp.Workbooks(1).Worksheets("Report4_Chart").select()
    xExcelApp.Selection.Copy()
    Any ideas on what I’m doing wrong?
    .
    ~Peter


  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: How to select/copy a chart in a chart sheet

    I don't have vb.net so try this for me...

    Code:
    xExcelApp.Workbooks(1).sheets("Report4_Chart").ChartArea.Copy
    or try this

    Code:
    xExcelApp.Workbooks(1).sheets("Report4_Chart").ChartArea.Copy()
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: How to select/copy a chart in a chart sheet

    To make it clear on these 3 object collections in a workbook:

    1. Worksheets: contains all worksheets: each member is a Worksheet object
    2. Charts: contains all chart sheets: each member is a Chart object
    3. Sheets: contains all worksheets and chart sheets: each member is either a Worksheet object or a Chart object. Noted that there is no Sheet object.

    A Chart object (chart sheet) is a member of Charts collection and it is also a member of Sheets collection.
    A Worksheet object is a member of Worksheets collection and it is also a member of Sheets collection.

    To specify a chart sheet, you cannot use Worksheets(index) but you have to use:
    Charts(index)
    or
    Sheets(index)
    where index is index-number or name.

    In your case, you can use either:

    xExcelApp.Workbooks(1).Charts("Report4_Chart").ChartArea.Copy

    or

    xExcelApp.Workbooks(1).Sheets("Report4_Chart").ChartArea.Copy
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  4. #4

    Thread Starter
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Thumbs up Re: How to select/copy a chart in a chart sheet

    Thanks for all the help. I was able to get it to work with:

    xExcelApp.Workbooks(1).Charts("Report4_Chart").ChartArea.Copy

    It's such a simple solution. Excellent. Thank you.
    .
    ~Peter


Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width