PDA

View Full Version : copying chart from one workbook to another using VB



aretai
08-05-2010, 09:57 PM
This question is about workbooks mainly.

I'm working on a workbook and calculate some values, based on which I create a graph. There is a new workbook created earlier in my code to which i would like to paste the new graph. Some of my code


Public wbk As Workbook
Set wbk = Workbooks.Add ' I use this to identify the new workbook
I don't use variable wbk anywhere else but in the part where I try to copy the chart:


ActiveSheet.ChartObjects("RadarGraph").Activate 'original workbook chart
ActiveChart.ChartArea.Copy ' here I copy the chart from original workbook
wbk.Activate 'here I try to activate the wbk workbook - new workbook that was created earlier
Worksheets("Results").Activate 'Here I activate the worksheet on the new workbook _
(it has the same name as the worksheet i was working with the original workbook
Worksheets("Results").Paste 'here I paste the chart
This however pastes the chart back to the original workbook instead of the new one. Where is the problem.

Thank you

Bob Phillips
08-06-2010, 01:08 AM
Have you tried



ActiveSheet.ChartObjects("RadarGraph").Activate
ActiveChart.ChartArea.Copy
wbk.Activate
Worksheets("Results").Activate
Range("G5").Select
Activesheet.Paste