Dim woexcel
Set woexcel = CreateObject("Excel.Application")
woexcel.DisplayAlerts = False
woexcel.Visible = True
woexcel.Workbooks.Open ("c:\activex.xlsx")
'将工作表第一张表格设置为活动
woexcel.Worksheets(1).Activate
'设置纸张类型
woexcel.ActiveSheet.PageSetup.PaperSize = 9
'打印方向设置为横向:
woexcel.ActiveSheet.PageSetup.Orientation = 2
2、相关参数的说明:
'xlLandscape 2 横向模式。
'xlPortrait 1 纵向模式。
'xlPaper11x17 17 11 英寸 x 17 英寸
'xlPaperA3 8 A3(297 毫米 x 420 毫米)
'xlPaperA4 9 A4(210 毫米 x 297 毫米)
'xlPaperA4Small 10 A4(小)(210 毫米 x 297 毫米)
'xlPaperA5 11 A5(148 毫米 x 210 毫米)
'xlPaperB4 12 B4(250 毫米 x 354 毫米)
'xlPaperB5 13 A5(148 毫米 x 210 毫米)
3、vba中支持系统常量,但是vbs中没有这些常量,应该换成相应数值,数值可以在vba帮助中查找。
Sub 打印()'
' 打印
'
'
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = ""
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.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)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = 100
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)