【问题标题】:How to add a printer setting into this VBA Code?如何在此 VBA 代码中添加打印机设置?
【发布时间】:2022-12-08 20:47:03
【问题描述】:

我在 Internet 上找到了以下非常有用的 VBA 代码,但我想添加一个额外的步骤来将打印机上的设置更改为“在一页上显示所有列”。我怎样才能做到这一点?

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

我是 VBA 的新手,我所做的只是在谷歌上搜索如何更改它,但没有任何效果。

【问题讨论】:

标签: excel vba


【解决方案1】:

尝试以下...

Application.PrintCommunication = False

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

Application.PrintCommunication = True

【讨论】:

  • 有效!谢谢你。我在代码的开头插入了代码,但首先它在没有设置打印机的情况下打印了一个额外的页面,然后它打印了我想要放在一页中的页面。我删除了“.PrintOut 以不打印额外的页面。非常感谢
  • 太好了,很高兴能帮上忙。而且,实际上,我将从代码中删除 .PrintOut,因为它并不真正属于您的情况。干杯!
猜你喜欢
  • 2019-02-24
  • 2021-07-26
  • 1970-01-01
  • 2010-11-08
  • 2017-12-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-14
  • 2023-03-18
相关资源
最近更新 更多