如下面:我将a1到j4合并,那我如何指定在a3单元格或是别的指定单元格内输入文本,谢谢大家!On Error Resume Next
If MSHFlexGrid1.TextMatrix(1, 2) = "" Then
MsgBox "没有数据导出", vbInformation, "提示"
Exit Sub
End If
Dim excelApp As Excel.Application
Set excelApp = New Excel.Application
Set excelApp = CreateObject("Excel.Application")
Dim exbook  As Excel.Workbook
Dim exsheet  As Excel.Worksheet
Set exbook = excelApp.Workbooks.Add
excelApp.SheetsInNewWorkbook = 1
excelApp.Visible = False '是否显示导出过程(true是)
excelApp.UserControl = True
Me.MousePointer = vbHourglass '控制鼠标为读取数据
'''''''''''''''''''''''''''''''''''''''''''表头设置'''''''''''''''''''''''''''''''''''''
With excelApp.ActiveSheet '表头合并
          .Range("a1:j4").Merge '合并
         
    
         .Range("a3:a3") = "入库单号:"
         .Range("b3:c3") = t
         .Range("d3:e3") = "仓库:"
         .Range("f3:f3") = DataGrid2.Columns("仓库").CellValue(DataGrid2.Book)
         .Range("g3:h3") = "入库日期:"
         .Range("i3:j3") = DataGrid2.Columns("入库日期").CellValue(DataGrid2.Book)
         .Range("a4:a4") = "供应商:"
         .Range("b4:c4") = DataGrid2.Columns("供应商").CellValue(DataGrid2.Book)
         .Range("d4:e4") = "入库类型:"
         .Range("f4:f4") = DataGrid2.Columns("入库类型").CellValue(DataGrid2.Book)
         .Range("g4:h4") = "打印日期"
         .Range("i4:j4") = Format$(Now, "yyyy-mm-dd")
       
       
       
        .Rows.HorizontalAlignment = xlVAlignCenter '
End With
With excelApp.ActiveSheet
        .Range("A1:j4").Borders.LineStyle = xlContinuous '表头边框线
End With

解决方案 »

  1.   

    啥意思,不太明白,直接写入不就可以了吗?
        excelapp.Cells(1, 1) = "XXX报表"
      

  2.   


    楼主看看这个:http://download.csdn.net/source/1262359
      

  3.   

    有称的代码,在最后
    With excelApp.ActiveSheet 
            .Range("A1:j4").Borders.LineStyle = xlContinuous '表头边框线 
    End With出现每个单元格都有边框
      

  4.   

    用我的代码,前面没有合并的语句,在最后加入语句 
    With excelApp.ActiveSheet 
            .Range("A1:j4").Borders.LineStyle = xlContinuous '表头边框线 
    End With 出现每个单元格都有边框
      

  5.   

    不用合并单元格,内部无边框,外部有实线边框.
    excel中录制宏,看具体写法,用于VB中
    以下是B10:D14内做法示例:
        Range("B10:D14").Select
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        Selection.Borders(xlEdgeLeft).LineStyle = xlNone
        Selection.Borders(xlEdgeTop).LineStyle = xlNone
        Selection.Borders(xlEdgeBottom).LineStyle = xlNone
        Selection.Borders(xlEdgeRight).LineStyle = xlNone
        Selection.Borders(xlInsideVertical).LineStyle = xlNone
        Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThick
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThick
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThick
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .Weight = xlThick
        End With
        Selection.Borders(xlInsideVertical).LineStyle = xlNone
        Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
      

  6.   


    那如果B10:D14中假如B11跟B12要合并,如何处理呢?
      

  7.   

    刚试了一下,其实用你的代码取代我下面的代码就是我要的功能了,谢谢你!
    With excelApp.ActiveSheet 
            .Range("A1:j4").Borders.LineStyle = xlContinuous '表头边框线 
    End With