在调用前通过代码设置打印属性

解决方案 »

  1.   

    ex1.Range("A2" & ":" & "H10" ).Select         '这里开始以下是设置A2到H10表格
    ex1.Selection.Borders(xlInsideHorizontal).LineStyle = 1
    ex1.Selection.Borders(xlInsideVertical).LineStyle = 1
    With ex1.Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With ex1.Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With ex1.Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With ex1.Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With ex1.Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With ex1.Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With ex1.ActiveSheet.PageSetup
        .PrintTitleRows = ""
        .PrintTitleColumns = ""
    End Withex1.ActiveSheet.PageSetup.PrintArea = "" '这里以下设置打印页面的上.下.左.右边距,打印方向(这里设置为横向),纸张(这里设置为A4纸)
    With ex1.ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .LeftMargin = ex1.Application.InchesToPoints(0.593)
        .RightMargin = ex1.Application.InchesToPoints(0.393)
        .TopMargin = ex1.Application.InchesToPoints(0.393)
        .BottomMargin = ex1.Application.InchesToPoints(0.393)
        .HeaderMargin = 0.5
        .FooterMargin = 0.5
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = 1
        .PrintQuality = 600
        .CenterHorizontally = False
        .CenterVertically = False
        .Orientation = 2
        .Draft = False
        .PaperSize = vbPRPSA4
        .FirstPageNumber = 2
        .Order = 2
        .BlackAndWhite = False
        .Zoom = 100
        .PrintErrors = xlPrintErrorsDisplayed
    End With
      

  2.   

    谢谢一楼指点,我已找到答案,我的方法是在Excel2000中定义宏,然后将模块直接在VB中使用,这种方法相对比较简单.如果不会请发贴.我会回.!