【发布时间】: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
【问题讨论】: