用宏录下你需要的动作啊
然后结合OFFICE光盘里的VBA帮助看看,调调就可以了
================================================================
举杯邀明月

解决方案 »

  1.   

    下面是我 写excel 的模块代码
    '将列数据转换成(1) 字符(A)
    Public Function GetCellName(Col As Long) As String
       If Col < 27 Then
          GetCellName = Chr(Col + 64)   Else
          GetCellName = Chr(Int((Col - 1) / 26) + 64) & Chr(((Col - 1) Mod 26) + 65)
       End If
    End Function'合并单元
     Public Sub CellMerge(ExSheet As Excel.Worksheet, rStart As Long, cStart As Long, rEnd As Long, cEnd As Long)
     Dim Slt  As String
     Slt = GetCellName(cStart) & CStr(rStart) & ":" & GetCellName(cEnd) & CStr(rEnd)
        With ExSheet
            .Range(Slt).Select
            With .Application.Selection
                .HorizontalAlignment = xlCenter
                .VerticalAlignment = xlBottom
                .WrapText = False
                .Orientation = 0
                .AddIndent = False
                .ShrinkToFit = False
            End With
            .Application.Selection.Merge
        End With
    End Sub
    ’将单元设置成 数字
    Public Sub CellNumber(ExSheet As Excel.Worksheet, rStart As Long, cStart As Long, rEnd As Long, cEnd As Long,Lng as long)
             Slt = GetCellName(cStart) & CStr(rStart) & ":" & GetCellName(cEnd) & CStr(rEnd)
       With ExSheet
            .Range(Slt).Select
            slt=mid("0.0000000000",1,2+lng)
            .Application.Selection.NumberFormatLocal = slt        With .Application.Selection
                .HorizontalAlignment = xlRight
                .VerticalAlignment = xlCenter
                .WrapText = False
                .Orientation = 0
                .AddIndent = False
                .ShrinkToFit = False
            End With
       End With
    End Sub
    '将单元设置成字符格式
    Public Sub CellChar(ExSheet As Excel.Worksheet, rStart As Long, cStart As Long, rEnd As Long, cEnd As Long)
             Slt = GetCellName(cStart) & CStr(rStart) & ":" & GetCellName(cEnd) & CStr(rEnd)
        With ExSheet
            .Range(Slt).Select
            .Application.Selection.NumberFormatLocal = "@"
             With .Application.Selection
                  .HorizontalAlignment = xlLeft
                  .VerticalAlignment = xlCenter
                  .WrapText = False
                  .Orientation = 0
                  .AddIndent = False
                  .IndentLevel = 0
                  .ShrinkToFit = False
            End With
        End With
    End Sub’单元化线
    Public Sub CellLine(ExSheet As Excel.Worksheet, rStart As Long, cStart As Long, rEnd As Long, cEnd As Long)
                
                Slt = GetCellName(cStart) & CStr(rStart) & ":" & GetCellName(cEnd) & CStr(rEnd)
         With ExSheet
                .Range(Slt).Select
                .Application.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
                .Application.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
                With .Application.Selection.Borders(xlEdgeLeft)
                    .LineStyle = xlContinuous
                    .Weight = xlThin
                    .ColorIndex = xlAutomatic
                End With
                With .Application.Selection.Borders(xlEdgeTop)
                    .LineStyle = xlContinuous
                    .Weight = xlThin
                    .ColorIndex = xlAutomatic
                End With
                With .Application.Selection.Borders(xlEdgeBottom)
                    .LineStyle = xlContinuous
                    .Weight = xlThin
                    .ColorIndex = xlAutomatic
                End With
                With .Application.Selection.Borders(xlEdgeRight)
                    .LineStyle = xlContinuous
                    .Weight = xlThin
                    .ColorIndex = xlAutomatic
                End With
                With .Application.Selection.Borders(xlInsideVertical)
                    .LineStyle = xlContinuous
                    .Weight = xlThin
                    .ColorIndex = xlAutomatic
                End With
                With .Application.Selection.Borders(xlInsideHorizontal)
                    .LineStyle = xlContinuous
                    .Weight = xlThin
                    .ColorIndex = xlAutomatic
                End With
          End With
    End Sub
    ’追加新sheet并命名
    Public Sub GetExSheet(ExBook As Excel.Workbook, ExSheet As Excel.Worksheet, cName As String, iCount As Long)
        With ExSheet
        
        If iCount <= .Application.Sheets.Count - 1 Then
            .Application.Sheets(iCount).Select
            .Application.Sheets(iCount).Name = cName
        Else
            .Application.Sheets(ExSheet.Application.Sheets.Count).Select
            .Application.Sheets.Add
            .Application.Sheets(ExSheet.Application.Sheets.Count - 1).Select
            .Application.Sheets(ExSheet.Application.Sheets.Count - 1).Name = cName
        End If
        End With
    End Sub希望对你有帮助 。。
    象楼上说的那样 看看 VBA 那个东东 很优秀的哦
      

  2.   

    VBA是什么东西,我不知道自己安装了没有,给个清楚的提示啊!
      

  3.   

    你上OFFICE开发论坛看看就知道了================================================================
    举杯邀明月
      

  4.   

    糟糕我好像没有安装VBA,等我看看