VB中如何给excel加边框

KOD 2004-12-30 08:19:47
如题
...全文
828 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
wumylove1234 2004-12-31
  • 打赏
  • 举报
回复
'画线
Public Sub DrawLine(bRow As Integer, bCol As Integer, eRow As Integer, eCol As Integer)
On Error Resume Next
xlSheet.Range(GetExcelCell(bRow, bCol) & ":" & GetExcelCell(eRow, eCol)).Select
xlApp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
xlApp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With xlApp.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlApp.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlApp.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlApp.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlApp.Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlApp.Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
'或者指定行,列号的Excel编码
Private Function GetExcelCell(Row As Integer, Col As Integer) As String
Dim nTmp1 As Integer
Dim nTmp2 As Integer
Dim sTmp As String
If Col <= 26 Then
sTmp = Chr(Asc("A") + Col - 1)
Else
nTmp1 = Col \ 26
If nTmp1 > 26 Then
Err.Raise 100000, , "列数过大,发生错误"
Exit Function
Else
sTmp = Chr(Asc("A") + nTmp1 - 1)
nTmp1 = Col Mod 26
sTmp = sTmp & Chr(Asc("A") + nTmp1 - 1)
End If
End If
GetExcelCell = sTmp & Row
End Function

这两个合起来用就行了.
白发程序猿 2004-12-31
  • 打赏
  • 举报
回复
xlsheet.Range("A1:E12").Borders.LineStyle = xlContinuous
xayzmb 2004-12-31
  • 打赏
  • 举报
回复
在EXCEL菜单的<工具>栏内找
dream747 2004-12-31
  • 打赏
  • 举报
回复
打开excel-》工具-》宏-》录制宏,然后看vba代码即可
KOD 2004-12-31
  • 打赏
  • 举报
回复
谢谢各位
xayzmb 2004-12-30
  • 打赏
  • 举报
回复
第一题:
你打开EXCEL
录一段宏
再修改一下就可以直接用了
KOD 2004-12-30
  • 打赏
  • 举报
回复
..........不能单独给分呀
晕~~~
KOD 2004-12-30
  • 打赏
  • 举报
回复
谢谢马上给分
第一问题应该是如何指定的区域加边框
如1a到e12
wangtopcool 2004-12-30
  • 打赏
  • 举报
回复
dim exWorksheet As Excel.Worksheet
.....
.....
exWorksheet.Columns.HorizontalAlignment = xlCenter
exWorksheet.Rows.VerticalAlignment = xlCenter
xayzmb 2004-12-30
  • 打赏
  • 举报
回复
改一下:
dim exl as new excel.appliction
....
...
exl.Cells.Select
exl.Selection.HorizontalAlignment = xlCenter
....
...
xayzmb 2004-12-30
  • 打赏
  • 举报
回复
dim exl as new excel.appliction
....
...
exl.Cells.Select.Selection.HorizontalAlignment = xlCenter
....
...
KOD 2004-12-30
  • 打赏
  • 举报
回复
还有一个问题
VB中如何让excel的数据居中显示。
最好有代码。
KOD 2004-12-30
  • 打赏
  • 举报
回复
问一个比较幼稚的问题,请问怎么录制宏呢?
xayzmb 2004-12-30
  • 打赏
  • 举报
回复
前提是你必须知道是区域位置
KOD 2004-12-30
  • 打赏
  • 举报
回复
如果每次选定的区域不一样也可以用这个方法吗?

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧