读书人

vb导出成EXECL,怎么在合并了的单元格内

发布时间: 2012-02-13 17:20:26 作者: rapoo

vb导出成EXECL,如何在合并了的单元格内指定位置输入某些文本
如下面:我将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.Bookmark)
.Range("g3:h3") = "入库日期:"
.Range("i3:j3") = DataGrid2.Columns("入库日期").CellValue(DataGrid2.Bookmark)
.Range("a4:a4") = "供应商:"
.Range("b4:c4") = DataGrid2.Columns("供应商").CellValue(DataGrid2.Bookmark)
.Range("d4:e4") = "入库类型:"
.Range("f4:f4") = DataGrid2.Columns("入库类型").CellValue(DataGrid2.Bookmark)
.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

[解决办法]
要这样就不能合并单元格。

你可以把这个区域内的单元格设置为无边框,整个区域设置成外部边框。

[解决办法]
不用合并单元格,内部无边框,外部有实线边框.
excel中录制宏,看具体写法,用于VB中
以下是B10:D14内做法示例:

VB code
    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
[解决办法]
先设置边框,再合并

读书人网 >VB

热点推荐