请问以下这段excel中的 VBA 如何及其改动后能 直接 在 VB6 中用?
谢谢了!由于版面过大,特用两个帖子贴出来。Sub a()
    Range("B2:H17").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = False
    End With
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With

解决方案 »

  1.   

    接上面    With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        Range("B2:H3").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = True
        End With
        Application.Left = 90.25
        Application.Top = 153.25
        Range("B4:H4").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = True
        End With
        Application.Left = 142
        Application.Top = 3.25
        Range("B11:H11").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .ShrinkToFit = False
            .MergeCells = True
        End With
        Range("B2:H3").Select
        ActiveCell.FormulaR1C1 = "fxbb"
        With ActiveCell.Characters(Start:=1, Length:=4).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
      

  2.   

    接上面
        Range("B4:H4").Select
        ActiveCell.FormulaR1C1 = "nb"
        With ActiveCell.Characters(Start:=1, Length:=2).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("B5").Select
        ActiveCell.FormulaR1C1 = "xm"
        With ActiveCell.Characters(Start:=1, Length:=2).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("B6").Select
        ActiveCell.FormulaR1C1 = "zc"
        With ActiveCell.Characters(Start:=1, Length:=2).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("B7").Select
        ActiveCell.FormulaR1C1 = "fsd"
        With ActiveCell.Characters(Start:=1, Length:=3).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("B8").Select
        ActiveCell.FormulaR1C1 = "srl"
        With ActiveCell.Characters(Start:=1, Length:=3).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
      

  3.   

    接上面    Range("B9").Select
        ActiveCell.FormulaR1C1 = "jkd"
        With ActiveCell.Characters(Start:=1, Length:=3).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("B10").Select
        ActiveCell.FormulaR1C1 = "jkg"
        With ActiveCell.Characters(Start:=1, Length:=3).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("C5").Select
        ActiveCell.FormulaR1C1 = "ndjh"
        With ActiveCell.Characters(Start:=1, Length:=4).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("D5").Select
        ActiveCell.FormulaR1C1 = "jdjh"
        With ActiveCell.Characters(Start:=1, Length:=4).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("E5").Select
        ActiveCell.FormulaR1C1 = "drwc"
        With ActiveCell.Characters(Start:=1, Length:=4).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("F5").Select
        ActiveCell.FormulaR1C1 = "ljwc"
        With ActiveCell.Characters(Start:=1, Length:=4).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("G5").Select
        ActiveCell.FormulaR1C1 = "ljcq"
        With ActiveCell.Characters(Start:=1, Length:=4).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
      

  4.   

    接上面    Range("H5").Select
        ActiveCell.FormulaR1C1 = "rjsxwc"
        With ActiveCell.Characters(Start:=1, Length:=6).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("B11:H11").Select
        ActiveCell.FormulaR1C1 = "yb"
        With ActiveCell.Characters(Start:=1, Length:=2).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("B12").Select
        ActiveCell.FormulaR1C1 = "xm"
        With ActiveCell.Characters(Start:=1, Length:=2).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("B13").Select
        ActiveCell.FormulaR1C1 = "zc"
        With ActiveCell.Characters(Start:=1, Length:=2).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("B14").Select
        ActiveCell.FormulaR1C1 = "fsd"
        With ActiveCell.Characters(Start:=1, Length:=3).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("B15").Select
        ActiveCell.FormulaR1C1 = "srl"
        With ActiveCell.Characters(Start:=1, Length:=3).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("B16").Select
        ActiveCell.FormulaR1C1 = "jkd"
        With ActiveCell.Characters(Start:=1, Length:=3).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Range("B17").Select
        ActiveCell.FormulaR1C1 = "jkg"
        With ActiveCell.Characters(Start:=1, Length:=3).Font
            .Name = "Times New Roman"
            .FontStyle = "常规"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
      

  5.   

    引用EXCEL对象
    然后在公共模块定义一个全局变量
    Public exl As Excel.Application
    需要使用EXCEL的地方添加如下代码
        Set exl = GetObject(, "Excel.Application") '查找一个正在运行的Excel拷贝
        If Err.Number <> 0 Then '如果 Excel 没有运行则
        Set exl = CreateObject("Excel.Application") '运行它
        End If
        Err.Clear '清除发生错误的 Err 对象
        On Error GoTo 0 '保留普通错误进程最后把你的那堆代码贴到后面即可
      

  6.   

    一定要引用EXCEL对象才行
      

  7.   

    谢谢啊!大哥。给分。
    能告述我你的email吗?
    :)
    希望多多向大哥请教了!