我的vba代码中的pdf打印输出的pagesetup似乎对我不起作用,有什么建议吗?

时间:2019-05-09 18:57:02

标签: excel vba

下面的代码似乎设置了正确的打印区域,但是当导出为pdf时,它仍然无法容纳一页上的所有列。我要寻找的最终结果是使所有列都适合一页(横向),但行不必适合一页。 PDF1 PDF2 SampleXLSX

  For k = 1 To wb.Sheets.Count
If wb.Sheets(k).Name Like "Facility List" Or _
   wb.Sheets(k).Name Like "TimestampExportReport" Then GoTo line3

    Application.PrintCommunication = True
    wb.Sheets(k).PageSetup.PrintArea = "$A$1:$H$" & wb.Sheets(k).Cells(wb.Sheets(k).Rows.Count, 1).End(xlUp).Row
    Application.PrintCommunication = False

With wb.Sheets(k).PageSetup
    .LeftMargin = Application.InchesToPoints(0)
    .RightMargin = Application.InchesToPoints(0)
    .TopMargin = Application.InchesToPoints(0)
    .BottomMargin = Application.InchesToPoints(0)
    .HeaderMargin = Application.InchesToPoints(0)
    .FooterMargin = Application.InchesToPoints(0)
    .Orientation = xlLandscape
    .PaperSize = ePaperSize
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = False
    .LeftHeader = ""
    .RightHeader = ""
    .LeftFooter = ""
    .CenterFooter = ""
    .RightFooter = ""

End With
    wb.Sheets(k).ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=strPathFile, _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=False
        Debug.Print k, strPathFile

 line3:

    Next k
End Sub

0 个答案:

没有答案