【009】Excel宏编程相关封装模块(边框细线、边框粗线、列宽、行高)_002_#VBA

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
该代码仅供学习,如商业转载请联系本人,非商业转载请注明出处

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

木易:_/

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值