XL: How to Programmatically Print All Embedded Charts on a Worksheet (213460)



The information in this article applies to:

  • Microsoft Excel 2000
  • Microsoft Excel 2002

This article was previously published under Q213460
For a Microsoft Excel 97 and earlier and Microsoft Excel 98 Macintosh Edition and earlier version of this article, see 117225.

SUMMARY

In Microsoft Excel, you can create a Microsoft Visual Basic for Applications macro that prints all embedded charts in an Excel worksheet. Each chart is printed on a separate page.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site: For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site: To create a sample macro that can print all the embedded charts in a worksheet, and print each chart to a separate page, follow these steps:
  1. Start Excel, and then open the workbook containing the worksheet with the embedded charts.
  2. Press ALT+F11 to start the Visual Basic Editor.
  3. On the Insert menu, click Module.
  4. In the module sheet, type or paste the following code:
    Sub PrintEmbeddedCharts()
         Dim ChartList As Integer
         Dim X As Integer
         ' Variable chartlist stores a count of all embedded charts.
         ChartList = ActiveSheet.ChartObjects.Count
         ' Increments the counter variable 'X' in a loop.
         For X = 1 To ChartList
             ' Selects the chart object.
             ActiveSheet.ChartObjects(X).Select
             ' Makes chart active.
             ActiveSheet.ChartObjects(X).Activate
             ' Prints one copy of active chart.
             ActiveChart.PrintOut Copies:=1
         Next
    End Sub
    					
  5. On the File menu, click Close and Return to Microsoft Excel.
  6. Select the worksheet that contains the embedded charts.
  7. on the Tools menu, point to Macro, and then click Macros.
  8. In the Macro name list, click PrintEmbeddedCharts, and then click Run.

Modification Type:MajorLast Reviewed:10/8/2003
Keywords:kbdtacode kbhowto kbProgramming KB213460