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:
DataBook.Sheets("Heat Transfer").Copy After:=OutputBook.Sheets(1)
VB Code:
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
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:
Dim sSheetName As String
sSheetName = "Sheet2" 'whatever sheet you want the charts on
For Each chtMyChart In OutputBook.Charts
chtMyChart.Location Where:=xlLocationAsObject, Name:=sSheetName
Next chtMyChart
Re: Copying charts in Excel using VBA
I will try that and see if it works.
Thanks for the help.
--Robert