Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Active worksheet help 1

Status
Not open for further replies.

elohelae

Technical User
Feb 25, 2011
27
GB
Good afternoon

I previously copied this code to get help with printing of multiple charts. The code works great however I would like to change it to just print off the first sheet which has the print macro button located on it. This print macro should now just run this code on the page with the charts.

I would appreciate any help.

Dim ws As Worksheet, co As ChartObject
For Each ws In ActiveWorkbook.Worksheets
For Each co In ws.ChartObjects
ActiveSheet.PageSetup.Orientation = xlLandscape
co.Chart.PrintOut
Next co
Next ws

I have tried removing the first for next loop with the ws and tried different derivations of code for the co for next loop and cannot seem to get it right.

Thanks :)
 
just remove the outer loop and replace the ws variable with the codename of the worksheet for which you want the charts printed.

Cheers,

Rofeu
 
Are you looking for one macro that will allow you to print /any/ page with a calling button on it?

So you've got six sheets, six buttons and each button should print the correct sheet?
 
hi,

your posted code only prints the active sheet and the active sheet NEVER CHANGES in the loop!!!
Code:
Sub PrintAllCharts()
'[b]this prints each chart on all sheets[/b]
    Dim ws As Worksheet, co As ChartObject
    For Each ws In ActiveWorkbook.Worksheets
        PrintChartsOnSheet ws
    Next ws
End Sub

Sub PrintActiveSheetCharts()
'[b]this prints each chart on active sheet[/b]
    Dim co As ChartObject
    PrintChartsOnSheet ActiveSheet
End Sub

Sub PrintChartsOnSheet(ws As Worksheet)
    With ws
        .PageSetup.Orientation = xlLandscape
        For Each co In .ChartObjects
            co.Chart.PrintOut
        Next co
    End With
End Sub

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 


I missplaces some declarations...
Code:
Sub PrintAllCharts()
'[b]this prints each chart on all sheets[/b]
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
        PrintChartsOnSheet ws
    Next ws
End Sub

Sub PrintActiveSheetCharts()
'[b]this prints each chart on active sheet[/b]
    PrintChartsOnSheet ActiveSheet
End Sub

Sub PrintChartsOnSheet(ws As Worksheet)
    Dim co As ChartObject
    With ws
        .PageSetup.Orientation = xlLandscape
        For Each co In .ChartObjects
            co.Chart.PrintOut
        Next co
    End With
End Sub

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top