在VB中如何设置EXCEL的某个单元格的内容为“数字”且该数字必须在某一
范围内,如10<数字<20,假如输入25则该单元格中的数字须以红色显示

解决方案 »

  1.   

    用SHELL打开EXCEL,再用SENDKEYS发送键去即可。按哪个键的,按多少次键自己试
      

  2.   

    具体查MSDN
    id=shell("EXCEL文件路径")
    sendkeys "A~"
      

  3.   

    在vb中应用microsoft excel object
    然后用下面代码就行
    还有其他功能可以到excel中录制宏
    然后编辑宏什么都有
    Dim objExcel As New Excel.Application
    objExcel.Workbooks.Open "c:\1.xls"
    objExcel.Visible = True
    With objExcel.ActiveSheet
        If Not IsNumeric(.Cells(1, 2).Value) Then
            .Range("a2").Select
            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 = 3
        End With
        End If
        Exit Sub
        If .Cells(1, 2).Value > 20 Or .Cells(1, 2) < 10 Then
            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 = 3
        End With
        End If
    End With
      

  4.   

    在excel中录制宏,在查看宏你就可以看到代码