Ivan
Many thanks for your assistance.
I've used the following code, but the organisation of the data has since
changed - does this mean that the code might have to be amended slightly? -
apologies if that is the case, as I do really appreciate your help with this.
There are still pivot tables and still the same number of charts, but the
charts are no longer pivot table charts - they are stand alone (embedded)
charts that are based on different data tables. The sheets containing the
charts now also have a summary of information relating to it, so I need to
copy the values and formatting for all the data and the charts on each sheet
into a new workbook. Will it make the copying out process easier if not
pivot-table charts?
Using the code you provided, I've tried to accomodate the copying of each
sheet as an array (not sure if this is correct)? Also, based on the code
below, it seems to fall over at the point of 'Chart.CopyPicture
Appearance:=xlScreen, Format:=xlPicture', saying that 'object doesn't support
this property or method'.
Sub CopyChart()
Dim ChartBook As Workbook, SourceBook As Workbook
Dim TmpSheets As Integer
Set SourceBook = ActiveWorkbook
TmpSheets = Application.SheetsInNewWorkbook
Application.SheetsInNewWorkbook = ActiveWorkbook.Charts.Count+ 6
Set ChartBook = Workbooks.Add
Application.SheetsInNewWorkbook = TmpSheets
TmpSheets = 1
'For Each Chart In SourceBook.Charts
' Chart.CopyPicture Appearance:=xlScreen, Format:=xlPicture
' With ChartBook.Sheets(TmpSheets)
' .Activate.PasteSpecial Format:="Picture (Enhanced Metafile)",
Link:=False, DisplayAsIcon:=False
' .Name = Chart.Name
' End With
' ActiveWindow.DisplayGridlines = False
' TmpSheets = TmpSheets + 1
'Next
For Each Chart In SourceBook.Sheets(Array("PC (Chart)-UK-MONTH", "PC
(Chart)-NI-MONTH"))
Chart.CopyPicture Appearance:=xlScreen, Format:=xlPicture
With ChartBook.Sheets(TmpSheets)
.Activate.PasteSpecial Format:="Picture (Enhanced Metafile)",
Link:=False, DisplayAsIcon:=False
.Name = Chart.Name
End With
ActiveWindow.DisplayGridlines = False
TmpSheets = TmpSheets + 1
Next
End Sub
- Show quoted text -
Hi Sarah,
This makes quite a bit of difference. I have re-worked it, and I
*think* this might do the trick for you, or close anyway:
Sub CopyChart()
Dim ChartBook As Workbook, SourceBook As Workbook
Dim TmpSheets As Integer, wkSheet As Worksheet
Dim ChartObj, ChartCount As Long
Set SourceBook = ActiveWorkbook
For Each wkSheet In SourceBook.Sheets
If wkSheet.ChartObjects.Count > 0 Then
ChartCount = ChartCount + 1
End If
Next
If ChartCount < 1 Then Exit Sub
TmpSheets = Application.SheetsInNewWorkbook
Application.SheetsInNewWorkbook = ChartCount
Set ChartBook = Workbooks.Add
Application.SheetsInNewWorkbook = TmpSheets
TmpSheets = 1
For Each wkSheet In SourceBook.Sheets
If wkSheet.ChartObjects.Count > 0 Then
With ChartBook.Sheets(TmpSheets)
.Activate
.Name = wkSheet.Name
wkSheet.Cells.Copy
.Paste
.ChartObjects.Delete
End With
ChartCount = 1
For Each ChartObj In wkSheet.ChartObjects
ChartObj.CopyPicture Appearance:=xlScreen, Format:=xlPicture
ChartBook.Sheets(TmpSheets) _
.PasteSpecial Format:="Picture (Enhanced Metafile)", _
Link:=False, DisplayAsIcon:=False
With ChartBook.Sheets(TmpSheets).Shapes(ChartCount)
.Top = ChartObj.Top
.Left = ChartObj.Left
End With
ChartCount = ChartCount + 1
Next
TmpSheets = TmpSheets + 1
End If
Next
End Sub
Let me know how you go.
Cheers,
Ivan.