Excel宏编程相关封装模块-第2期
1. 说明
该模块是根据Excel宏编程官网及录制时相关操作进行编写的,如有不足之处,望批评指正!!!
2. 代码
2.1 修改网格边缘为细线
选中一定的区域,对每个格子添加设置细线
Function AssistThinFrame(H1, L1, H2, L2)
'对于选中的区域加上细网格线 _ ,,首位_,,末位
Range(Cells(H1, L1), Cells(H2, L2)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Function
效果如下
2.2 对选中的区域添加粗外边框
对选中区域的外边框设置为粗外边框
Function AssistThickFrame(H1, L1, H2, L2)
'对于选中的区域加上粗外边框 _ ,,首位_,,末位
Range(Cells(H1, L1), Cells(H2, L2)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
效果如下
2.3 调整列宽
对指定列修改列宽
Function AssistColumnWidth(L1, L2, Width)
'对于选中的列调整列宽 _ 首列_末列_宽度
Range(Columns(L1), Columns(L2)).Select
Selection.ColumnWidth = Width
End Function
2.4 调整行高
对指定行修改行宽
Function AssistRowHeight(H1, H2, Height)
'对于选中的行调整行高 _ 首列_末列_高度
Rows(H1 & ":" & H2).Select
Selection.RowHeight = Height
End Function
参考地址:https://docs.microsoft.com/zh-cn/office/client-developer/excel/excel-home?redirectedfrom=MSDN
该代码仅供学习,如商业转载请联系本人,非商业转载请注明出处