excel vba not exporting pagesetup to pdf correctly

后端 未结 3 1954
-上瘾入骨i
-上瘾入骨i 2020-12-11 05:41

I have code which formats a worksheet to the desired setup and layout (one page wide and tall in landscape). When I run the code (part of a long macro) it formats the pagese

3条回答
  •  旧巷少年郎
    2020-12-11 05:58

    I have found what seems to be the solution:

    Application.PrintCommunication = False
        With ActiveSheet.PageSetup
            .Orientation = xlLandscape
            .Zoom = False
            '.PrintArea = Worksheets(ReportWsName).UsedRange
            .FitToPagesWide = 1
            '.FitToPagesTall = 1
        End With
    Application.PrintCommunication = True
    

    I needed to add the Application.PrintCommunication part to the equation. For whatever reason Excel would overwrite the settings I was putting if I ran the code without it.

提交回复
热议问题