Print Charts

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have twelve workbooks that each contain 2 worksheets. One worksheet
contains data and the other contains a chart.

Is there a way that I can call up the individual workbooks and then print
out just the chart tab, save and call up the next workbook. All this done
with one Macro.

Thanks
Frank
 
Little doubt that it could be done. You could write code that lists all
workbook's complete paths/names and have it open them one at a time, find a
sheet with a chart on it (be nice if chart sheets all had same name), and
print the sheet within a loop.
Another way would be to have only those files in a specific folder and have
your macro simply access each .xls file in the folder in turn (except for
itself) and then do same process regarding finding the chart sheet(s) and
printing them.
 
give this one a try.
run this, then a dialog comes up and select a folder that has your files.
I presume your files are in a same folder. this would try to print every
graph in workbooks in the folder, as i'm not sure your graphs are in
worksheets or in graph sheet.

Sub printcharts()
Dim wb, fd
Dim sh As Worksheet
Dim chobj As ChartObject
Dim ch As Chart
Dim xlFile As String
Dim MyPath As String

Set fd = Application.FileDialog(msoFileDialogFolderPicker)

If fd.Show = -1 Then
MyPath = fd.SelectedItems(1)
Else
Exit Sub
End If
ChDir MyPath
xlFile = Dir("*.xls")
On Error Resume Next
Application.DisplayAlerts = False
Do While xlFile <> ""
If ThisWorkbook.Name <> xlFile Then
Set wb = Workbooks.Open(MyPath & _
Application.PathSeparator & xlFile)
End If
'print every worksheets that have graphs
For Each sh In worksheets
Set chobj = Nothing
Set chobj = sh.ChartObjects(1)
If Not chobj Is Nothing Then
sh.PrintOut 'preview:=True
End If
Next
'print every Graph sheets
For Each ch In Charts
ch.PrintOut 'preview:=True
Next
wb.Close SaveChanges:=False
xlFile = Dir
Loop
End Sub

keizi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top