【问题标题】:Print Preview and setting properties with vba使用 vba 打印预览和设置属性
【发布时间】:2023-01-30 07:15:49
【问题描述】:

我有一个 Excel 工作表,我有一个打印预览模块,其中设置了多个属性。当我进入实际的打印预览时,我总是必须在一页上设置方向、缩放和适合文档。问题是我设置了一个模块来处理这个问题,但它不工作。任何帮助,将不胜感激。

这是我的代码模块:

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

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    要使.FitToPagesWide = 1.FitToPagesTall = False生效,您需要将.Zoom设置为False

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

    这基本上与您在页面设置设置中更改单选按钮的值具有相同的效果。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多