Results 1 to 3 of 3

Thread: Copying charts in Excel using VBA

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    2

    Copying charts in Excel using VBA

    I am very new to VBA and I need help with copying a chart from one workbook to another. The problem is that in the workbook I am copying from, the chart is a separate page. However, I want to copy just the chart and not have it be an entire page. Here is the code I am using:

    VB Code:
    1. DataBook.Sheets("Heat Transfer").Copy After:=OutputBook.Sheets(1)
    VB Code:
    1. DataBook.Sheets("Heat Flux").Copy After:=OutputBook.Sheets(2)
    Code:
    DataBook.Sheets("Skin Temperature").Copy After:=OutputBook.Sheets(3)
    I think I am transfering the code into this message the right way but if it is awkward, I am sorry.

    Thanks for any help, it will be appreciated
    -Robert

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Copying charts in Excel using VBA

    Knagulf
    You could copy all the chgarts you need into the OutputBook workbook as seperate pages and after you have all them in that workbook you could then loop through the Charts collection and change the 'Location' such that each chart is an object on a particular worksheet.

    Something like the following will achieve this.

    VB Code:
    1. Dim sSheetName As String
    2.    
    3.     sSheetName = "Sheet2" 'whatever sheet you want the charts on
    4.    
    5.     For Each chtMyChart In OutputBook.Charts
    6.         chtMyChart.Location Where:=xlLocationAsObject, Name:=sSheetName
    7.     Next chtMyChart
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    2

    Re: Copying charts in Excel using VBA

    I will try that and see if it works.

    Thanks for the help.
    --Robert

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