Home > Blockchain >  How to add a printer setting into this VBA Code?
How to add a printer setting into this VBA Code?

Time:12-08

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.

CodePudding user response:

Try the following...

Application.PrintCommunication = False

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

Application.PrintCommunication = True
  • Related