0

I found the below VBA code on the internet which is very helpful, but I would like to add an extra step to change the settings on the printer to "Fit All Columns on One Page". How Can I do that?

Sub PrintFirstFilterItems()
'downloaded from contextures.com
 'prints a copy of pivot table
 'for each item in
 'first Report Filter field
On Error Resume Next
Dim ws As Worksheet
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Set ws = ActiveSheet
Set pt = ws.PivotTables(1)
Set pf = pt.PageFields(1)

If pf Is Nothing Then Exit Sub

For Each pi In pf.PivotItems
  pt.PivotFields(pf.Name) _
        .CurrentPage = pi.Name
  ActiveSheet.PrintOut  'for printing
  'ActiveSheet.PrintPreview  'for testing
Next pi
End Sub


I need the code to change the printer settings to this

I am new on VBA, and all I did was search on google how to change it but nothing worked.

1

1 Answer 1

1

Try the following...

Application.PrintCommunication = False

With ActiveSheet
    With .PageSetup
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With
End With

Application.PrintCommunication = True
Sign up to request clarification or add additional context in comments.

3 Comments

It worked! Thank you. I inserted the code at the beginning of my code but first it printed an extra page without the printer being set up, and then it printed the pages I wanted fitting in 1 page. I removed ".PrintOut to not have the extra page printed. Thank you so much
That's great, glad I could help. And, actually, I'll remove .PrintOut from the code, since it doesn't really belong there in your case. Cheers!
Good stuff here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.