自已录制一个宏就可以了    With xlSheet.PageSetup
        .LeftMargin = Application.InchesToPoints(0.94488188976378)
        .RightMargin = Application.InchesToPoints(0.94488188976378)
        .TopMargin = Application.InchesToPoints(0.78740157480315)
        .BottomMargin = Application.InchesToPoints(0.78740157480315)
        .HeaderMargin = Application.InchesToPoints(0.511811023622047)
        .FooterMargin = Application.InchesToPoints(0.511811023622047)
        .PaperSize = xlPaperA4
    End With

解决方案 »

  1.   

    '如果你以后遇到类似的问题,在Excel中录制一个宏就可以明白该怎么写程序了,完整代码如下:
    Private Sub Command1_Click()
        Dim xlApp As Excel.Application
        Dim xlBook As Excel.Workbook
        Dim xlSheet As New Excel.Worksheet
        Dim strFile As String
        Dim strRange As String
        
        On Error GoTo ErrorHandler
        
        strFile = "c:\abc.xls"
        
        Screen.MousePointer = 11
        Set xlApp = New Excel.Application
        Set xlBook = xlApp.Workbooks.Add
        Set xlSheet = xlBook.Worksheets("Sheet1")
        
        With xlSheet
            .LeftMargin = xlApp.InchesToPoints(1) '1英吋
            .RightMargin = xlApp.InchesToPoints(1)
            .TopMargin = xlApp.InchesToPoints(0.8)
            .BottomMargin = xlApp.InchesToPoints(0.8)
            .HeaderMargin = xlApp.InchesToPoints(0.5)
            .FooterMargin = xlApp.InchesToPoints(0.5)
            .PaperSize = xlPaperA4
        End With
        
        xlSheet.SaveAs strFile
        Set xlSheet = Nothing
        xlBook.Close
        Set xlBook = Nothing
        xlApp.QUIT
        Set xlApp = Nothing
        
        Screen.MousePointer = 0
        
    ErrorHandler:
        MsgBox Err.DescriptionEnd Sub