在VB中如何设置excel的左右的页边距,假如都设置为1.0,请问如何编写,给出代码者多给分

解决方案 »

  1.   

        With xlsheet.PageSetup
            .LeftMargin = Application.InchesToPoints(0.393700787401575)
            .RightMargin = Application.InchesToPoints(0.393700787401575)
        End With
      

  2.   

    '先引用excel *.0 object library
    Private Sub Command3_Click()    Set ex = CreateObject("Excel.Application")
        Set wb = ex.Workbooks.Add '新建excel
        Set sh = wb.Sheets(1)   '第一个工作表
        
         With ActiveSheet.PageSetup
            .PrintTitleRows = ""
            .PrintTitleColumns = ""
        End With
        ActiveSheet.PageSetup.PrintArea = ""
        With ActiveSheet.PageSetup
            .LeftHeader = ""
            .CenterHeader = ""
            .RightHeader = ""
            .LeftFooter = ""
            .CenterFooter = ""
            .RightFooter = ""
            .LeftMargin = Application.InchesToPoints(0.393700787401575)
            .RightMargin = Application.InchesToPoints(0.393700787401575)
            .TopMargin = Application.InchesToPoints(0.984251968503937)
            .BottomMargin = Application.InchesToPoints(0.984251968503937)
            .HeaderMargin = Application.InchesToPoints(0.511811023622047)
            .FooterMargin = Application.InchesToPoints(0.511811023622047)
            .PrintHeadings = False
            .PrintGridlines = False
            .PrintComments = xlPrintNoComments
            .PrintQuality = 300
            .CenterHorizontally = False
            .CenterVertically = False
            .Orientation = xlPortrait
            .Draft = False
            .PaperSize = xlPaperA4
            .FirstPageNumber = xlAutomatic
            .Order = xlDownThenOver
            .BlackAndWhite = False
            .Zoom = 100
            .PrintErrors = xlPrintErrorsDisplayed
        End With     ex.Visible = True
        Set ex = Nothing
        Set wb = Nothing
        Set sh = Nothing
    End Sub
      

  3.   

    录制宏吧,通过这种方法,以后再操作excel或者word中有什么问题基本都能解决了。步骤是:开始录制宏---进行你想要的效果的操作---停止宏---查看宏命令。