FitToPagesTall方法问题

时间:2017-09-26 12:15:45

标签: excel-vba vba excel

我遇到了For Each循环和FitToPages的问题。文件有82张。

这是我的代码:

Sub printSet()
    Dim sht As Worksheet
    Dim lasrow As Integer
    For Each sht In ThisWorkbook.Worksheets
        lasrow = sht.Cells(sht.Rows.count, 3).End(xlUp).Row
        sht.PageSetup.PrintArea = Range("A1:D" & lasrow).Address
        sht.PageSetup.FitToPagesTall = 1
    Next
End Sub

完美地选择了打印区域......但是每张纸在打印预览窗口中分为4页,这一点都不好。

哪里出错?因为文件正在编译而没有任何错误。

谢谢。

1 个答案:

答案 0 :(得分:1)

发现它!我在PageSetup中错过了.Zoom = False:

Sub printSet()
    Dim sht As Worksheet
    Dim lasrow As Integer
    For Each sht In ThisWorkbook.Worksheets
        lasrow = sht.Cells(sht.Rows.count, 3).End(xlUp).Row
        sht.PageSetup.PrintArea = Range("A1:D" & lasrow).Address
        With sht.PageSetup
            .Zoom = False
            .FitToPagesTall = 1
        End With
    Next