没有人会吗?
要出人命了!

解决方案 »

  1.   

    '试试
    Dim i As Integer
        Dim oExcel As Object
        Dim oBook As Object
        Dim oSheet As Object
        
        Set oExcel = CreateObject("Excel.Application")
        Set oBook = oExcel.workbooks.Add
        Set oSheet = oBook.Worksheets(1)
        oExcel.Visible = True
        oSheet.Range("A1:H1").Select
        
        With oExcel.Selection
            '.HorizontalAlignment = -4107  '< ------错误从这里开始
            .VerticalAlignment = -4108
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = False
        End With'    MyMonth = InputBox("请输入Excel文件的月份")'    If CInt(MyMonth) < 1 And CInt(MyMonth) > 12 Then
    '        MsgBox "输入有误!"
    '        Exit Sub
    '    End If    oExcel.Selection.Merge
    '    oSheet.Range("A1:H1").Select
        oExcel.Selection.FormulaR1C1 = "分类信息查询"    With oExcel.ActiveCell.Characters(Start:=1, Length:=20).Font
            .Name = "宋体"
            .FontStyle = "加粗"
            .Size = 18
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = -4142
            .ColorIndex = -4105
        End With    
        oSheet.Cells(2, 1).Value = "序号"
        oSheet.Cells(2, 2).Value = "姓名"
        oSheet.Cells(2, 3).Value = "身份证号码"
        oSheet.Cells(2, 4).Value = "工资总额"
        oSheet.Cells(2, 5).Value = "个人比例"
        oSheet.Cells(2, 6).Value = "单位比例"
        oSheet.Cells(2, 7).Value = "累积余额"
        oSheet.Cells(2, 8).Value = "工资性质"    oSheet.Columns("A:A").ColumnWidth = 4
        oSheet.Columns("B:B").ColumnWidth = 8
        oSheet.Columns("C:C").ColumnWidth = 18
        oSheet.Columns("D:D").ColumnWidth = 8
        oSheet.Columns("E:E").ColumnWidth = 8
        oSheet.Columns("F:F").ColumnWidth = 8
        oSheet.Columns("G:G").ColumnWidth = 10
        oSheet.Columns("H:H").ColumnWidth = 8    For i = 3 To RSObj.RecordCount + 2
            oSheet.Cells(i, 1).Value = RSObj("xh")
            oSheet.Cells(i, 2).Value = RSObj("xm")
            oSheet.Cells(i, 3).Value = RSObj("sfz")
            oSheet.Cells(i, 4).Value = RSObj("gzze")
            oSheet.Cells(i, 5).Value = RSObj("grbl")
            oSheet.Cells(i, 6).Value = RSObj("dwbl")
            oSheet.Cells(i, 7).Value = RSObj("ljye")
            oSheet.Cells(i, 8).Value = RSObj("gzxz")
            RSObj.MoveNext
        Next
        
        Mystr = "A2:H" & Trim(Str(RSObj.RecordCount + 2))    oSheet.Range(Mystr).Select    With oExcel.Selection.Borders(7)
            .LineStyle = 1
            .Weight = 2
            .ColorIndex = -4105
        End With
        
        With oExcel.Selection.Borders(8)
            .LineStyle = 1
            .Weight = 1
            .ColorIndex = -4105
        End With
        
        With oExcel.Selection.Borders(9)
            .LineStyle = 1
            .Weight = 1
            .ColorIndex = -4105
        End With
        
        With oExcel.Selection.Borders(10)
            .LineStyle = 1
            .Weight = 1
            .ColorIndex = -4105
        End With
        
        With oExcel.Selection.Borders(11)
            .LineStyle = 1
            .Weight = 1
            .ColorIndex = -4105
        End With
        
        With oExcel.Selection.Borders(12)
            .LineStyle = 1
            .Weight = 1 - 4105
        End With
        
        oSheet.Range("E:E").NumberFormatLocal = "0.00"
        oSheet.Range("F:F").NumberFormatLocal = "0.00"
        oSheet.Range("G:G").NumberFormatLocal = "0.00"'    oBook.SaveAs "D:\BaguijinWork\baguijin\gjj\Book2.xls"
        
        '************
        '* 打印预览 *
        '************
        oSheet.PrintPreview
        'oSheet.PrintOut
        oExcel.Quit
        Set oSheet = Nothing
        Set oBook = Nothing
        Set oExcel = Nothing