×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

VBA Printing all charts in workbook - blank pages

VBA Printing all charts in workbook - blank pages

VBA Printing all charts in workbook - blank pages

(OP)
I am using the following code to print all charts in Excel 2010 workbook. However, it does not print all charts. Some are either partial chart or blank pages. any ideas? (I copied and pasted this VBA)I have tried another VBA code as well and it was the same.

Option Explicit
Sub PrintCharts()
'-------------------------------------------------------------------
'---Script: PrintCharts---------------------------------------------
'---Created by: Ryan Wells (wellsr.com)-----------------------------
'---Date: 04/2015---------------------------------------------------
'---Description: Orients and Prints all charts in an Excel Workbook-
'-------------------------------------------------------------------
Application.ScreenUpdating = False
Dim ch As Object
Dim sh As Worksheet
Dim icount As Integer
icount = 0
'Print Chart Objects
For Each sh In ActiveWorkbook.Worksheets
sh.Activate
For Each ch In sh.ChartObjects
If ch.Height < ch.Width Then
ch.Chart.PageSetup.Orientation = xlLandscape
Else
ch.Chart.PageSetup.Orientation = xlPortrait
End If
icount = icount + 1
ch.Chart.PrintOut
Next ch
Next sh

'Print Charts
For Each ch In ActiveWorkbook.Charts
icount = icount + 1
ch.PrintOut
Next ch

MsgBox "Printing " & icount & " charts from Workbook " _
& ActiveWorkbook.Name & ".", vbInformation, "Print Charts"

Application.ScreenUpdating = True
End Sub


RE: VBA Printing all charts in workbook - blank pages

hi,

CODE

Sub PrintCharts()
 '-------------------------------------------------------------------
 '---Script: PrintCharts---------------------------------------------
 '---Created by: Ryan Wells (wellsr.com)-----------------------------
 '---Date: 04/2015---------------------------------------------------
 '---Description: Orients and Prints all charts in an Excel Workbook-
 '-------------------------------------------------------------------
    Application.ScreenUpdating = False
    Dim ch As Object
    Dim sh As Object
    Dim icount As Integer, x
    icount = 0
    'Print Chart Objects
    For Each sh In ActiveWorkbook.Sheets
        If sh.Type = xlWorksheet Then
            For Each ch In sh.ChartObjects
                If ch.Height < ch.Width Then
                ch.Chart.PageSetup.Orientation = xlLandscape
                Else
                ch.Chart.PageSetup.Orientation = xlPortrait
                End If
                icount = icount + 1
                ch.Chart.PrintOut
            Next ch
        Else
            If sh.ChartArea.Height < sh.ChartArea.Width Then
                sh.PageSetup.Orientation = xlLandscape
            Else
                sh.PageSetup.Orientation = xlPortrait
            End If
            icount = icount + 1
            sh.PrintOut
        End If
    Next sh
    
    MsgBox "Printing " & icount & " charts from Workbook " _
    & ActiveWorkbook.Name & ".", vbInformation, "Print Charts"
    
    Application.ScreenUpdating = True
End Sub 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close