|
|
|
|
|
|
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
If ActiveWorkbook.Charts.Count > 0 Then
With Application
.ScreenUpdating = False
If Val(.Version) >= 9 Then
.ShowWindowsInTaskbar = False
End If
On Error GoTo ErrHandle
ActiveWorkbook.Charts.Copy
For Each Cht In ActiveWorkbook.Charts
For Each oSeries In Cht.SeriesCollection
With oSeries
.Name = .Name
.Values = .Values
.XValues = .XValues
End With
Next
Next
szNewFile = .GetSaveAsFilename("BookOCharts.xls", _
"Excel Files (*.xls), *.xls")
With ActiveWorkbook
If szNewFile <> "False" Then
.SaveAs szNewFile
.Close
Else
.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:
|
- Open an Excel Workbook
- Copy the code
- Press Alt + F11 to open the Visual Basic Editor (VBE)
- Select INSERT > MODULE from the menubar
- Paste code into the right pane
- Press Alt+Q to return to Excel
- Save workbook before any other changes
|
Test the code:
|
- Go to TOOLS > MACRO > MACROS
- When the dialog appears, select CopyChartsToNewBookAndDelinkThemToo
- Press Run
- 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.
|
|