Excel

Copy Chart Sheets to a New Workbook

Ease of Use

Easy

Version tested with

2000, 2002 

Submitted by:

Justinlabenne

Description:

Copies and delinks all chart sheets in the current workbook to a new workbook 

Discussion:

If you ever want to copy your current chart sheets (as is) to a new file, maybe for weekly, monthy, or yearly reporting, this code will copy all your chart sheets to a new workbook, breaking the links to the originla file, leaving you with fixed charts of your data. The code allows you to select a file name and the new folder location for the new workbook also. 

Code:

instructions for use

			

Option Explicit Sub CopyChartsToNewBookAndDelinkThemToo() Dim Cht As Chart Dim oSeries As Series Dim wks As Worksheet Dim szNewFile As String ' Do we have any charts? If ActiveWorkbook.Charts.Count > 0 Then ' if yes: ' No screen flicker, or new workbook appearance: With Application .ScreenUpdating = False If Val(.Version) >= 9 Then .ShowWindowsInTaskbar = False End If On Error GoTo ErrHandle ' This copies the charts all to a new workbook ' The new workbook becomes the active workbook ' *Amended by Jon Peltier ActiveWorkbook.Charts.Copy ' Delink all the charts from the original workbook For Each Cht In ActiveWorkbook.Charts For Each oSeries In Cht.SeriesCollection With oSeries .Name = .Name .Values = .Values .XValues = .XValues End With Next Next ' Where and under what name to store our new workbook of charts ' Initial file name is [BookOCharts], user changes to suit szNewFile = .GetSaveAsFilename("BookOCharts.xls", _ "Excel Files (*.xls), *.xls") With ActiveWorkbook If szNewFile <> "False" Then ' Save it and close it .SaveAs szNewFile .Close Else ' if it was canceled .Close False End If End With ErrExit: If Val(.Version) >= 9 Then .ShowWindowsInTaskbar = True End If .ScreenUpdating = True End With Else MsgBox "No chart sheets are available to copy", 64 End If Exit Sub ErrHandle: MsgBox Err.Description GoTo ErrExit End Sub

How to use:

  1. Open an Excel Workbook
  2. Copy the code
  3. Press Alt + F11 to open the Visual Basic Editor (VBE)
  4. Select INSERT > MODULE from the menubar
  5. Paste code into the right pane
  6. Press Alt+Q to return to Excel
  7. Save workbook before any other changes
 

Test the code:

  1. Go to TOOLS > MACRO > MACROS
  2. When the dialog appears, select CopyChartsToNewBookAndDelinkThemToo
  3. Press Run
  4. Any chart sheets will be copied to a new workbook
 

Sample File:

Delink and Copy.zip 8.73KB 

Approved by mdmackillop


This entry has been viewed 153 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express