excel 打印预览和使用vba设置属性

yftpprvb  于 2023-01-31  发布在  其他
关注(0)|答案(1)|浏览(255)

我有一个excel工作表,我有一个打印预览模块,其中设置了几个属性。当我去实际的打印预览,我总是要设置方向,缩放比例和适合文件在一页上。问题是,我有一个模块设置来照顾,但不是;It“不起作用,任何帮助都将不胜感激。
下面是我的代码模块:

Sub PrintFrm()

Dim lr As Long
Dim lc As Long

lr = Cells(Rows.Count, 1).End(xlUp).Row
lc = Cells(1, Columns.Count).End(xlToLeft).Column

Application.ScreenUpdating = False
Application.DisplayAlerts = False
    
    Application.PrintCommunication = True
    ActiveSheet.PageSetup.PrintArea = ""
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .FitToPagesWide = 1
        .FitToPagesTall = False
        .Orientation = xlLandscape
        .LeftHeader = "Page &P of &N"
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = "Cycle Count"
         .CenterFooter = Format(Now, "mm/dd/yyyy" & " at " & "hh:mm:ss")
        .RightFooter = "Printed by: " & Application.UserName
        .LeftMargin = Application.InchesToPoints(0.7)
        .RightMargin = Application.InchesToPoints(0.7)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .PaperSize = xlPaperLetter
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = 100
        .PrintErrors = xlPrintErrorsDisplayed
    End With
    Application.PrintCommunication = True
    Cells.Select
    With Selection.Font
        .Name = "Times New Roman"
    End With
    Range("C3:C" & lr).Select
    With Selection
        .HorizontalAlignment = xlLeft
        .VerticalAlignment = xlCenter
    End With

    Application.PrintCommunication = True

Application.ScreenUpdating = True
Application.DisplayAlerts = True

Application.Dialogs(xlDialogPrint).Show
ActiveWindow.SelectedSheets.PrintOut

End Sub
wljmcqd8

wljmcqd81#

宏记录器在这一点上是误导的,因为它不包括它,但是要使.FitToPagesWide = 1.FitToPagesTall = False生效,您需要将.Zoom设置为False

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

这与在“页面设置”中更改单选按钮的值的效果基本相同。

请注意,我无法重现.Orientation的问题。

相关问题