Private Sub 一键打印_Click()
Dim sht As Worksheet
For Each sht In Worksheets
a = sht.Range("A1:N50").Find("报告发出日期", lookat:=xlWhole).Row '搜索出“报告发出日期”所在行数赋值给a
sht.PageSetup.PrintArea = "A1:N" & a '设置打印范围(PrintArea):单元格A1到(N列,"报告发出日期"所在行)的范围
sht.PageSetup.Orientation = xlLandscape '页面方向(Orientation):横向(xlLandscape)、纵向(xlPortrait)
sht.PageSetup.PaperSize = xlPaperA4 '打印纸张类型:xlPaperA4 :(A4);xlPaperA3 :(:A3);xlPaperB4 : (B4)
sht.PageSetup.LeftMargin = Application.CentimetersToPoints(0.1) '页边距:左(LeftMargin):0.1厘米
sht.PageSetup.RightMargin = Application.CentimetersToPoints(0.1) '页边距:右(RightMargin):0.1厘米
sht.PageSetup.TopMargin = Application.CentimetersToPoints(1) '页边距:上(TopMargin):1厘米
sht.PageSetup.BottomMargin = Application.CentimetersToPoints(0.1) '页边距:下(BottomMargin):1厘米
sht.PageSetup.HeaderMargin = Application.CentimetersToPoints(1) '页边距:页眉(HeaderMargin):1厘米
sht.PageSetup.FooterMargin = Application.CentimetersToPoints(0.5) '页边距:页脚(FooterMargin):0.5厘米
sht.PageSetup.Zoom = 100 '100:缩放比例100%
sht.PageSetup.CenterHorizontally = True '水平居中
sht.PageSetup.PrintErrors = xlPrintErrorsDisplayed '工作表打印错误单元格打印为(E):显示值/<空白> xlPrintErrorsBlank/-- xlPrintErrorsDash/#N/A xlPrintErrorsNA
If sht.Visible = xlSheetVisible Then '只打印可见工作表
sht.PrintOut Copies:=1, ActivePrinter:="Microsoft Print to PDF" '打印机名称(ActivePrinter):="Microsoft Print to PDF",双引号内根据实际的打印机名称进行填写
End If
Next
End Sub
VB语言-打印机一键打印
于 2023-01-31 14:08:56 首次发布