Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2653|回复: 5

[已解决]选中的单元格打上边框,代码非得这么长吗?

[复制链接]
发表于 2014-9-11 12:18 | 显示全部楼层 |阅读模式
本帖最后由 billyzhang0609 于 2014-9-11 12:46 编辑

各位高手

用录制宏,得到的代码忒长了,有没有办法简化?

   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
    Selection.Font.Bold = True
    Range("A1:D2").Select
    With Selection.Font
        .Name = "宋体"
        .Size = 20
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ThemeColor = xlThemeColorLight1
        .TintAndShade = 0
        .ThemeFont = xlThemeFontMinor
    End With
最佳答案
2014-9-11 12:37
Selection.Borders(xlEdgeLeft).LineStyle = xlContinuous
Selection.Borders(xlEdgeTop).LineStyle = xlContinuous
Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
以此类推
发表于 2014-9-11 12:36 | 显示全部楼层
    With Selection
        .Borders(xlEdgeLeft).LineStyle = xlContinuous
        .Borders(xlEdgeTop).LineStyle = xlContinuous
        .Borders(xlEdgeBottom).LineStyle = xlContinuous
        .Borders(xlEdgeRight).LineStyle = xlContinuous
    End With

评分

参与人数 1 +5 金币 +5 收起 理由
suye1010 + 5 + 5 很给力!

查看全部评分

回复

使用道具 举报

发表于 2014-9-11 12:37 | 显示全部楼层    本楼为最佳答案   
Selection.Borders(xlEdgeLeft).LineStyle = xlContinuous
Selection.Borders(xlEdgeTop).LineStyle = xlContinuous
Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
以此类推
回复

使用道具 举报

发表于 2014-9-11 13:22 | 显示全部楼层
本帖最后由 suye1010 于 2014-9-11 14:36 编辑

一句就行了……
  1. Selection.Borders.Weight = xlThin
复制代码

评分

参与人数 1 +5 金币 +10 收起 理由
suye1010 + 5 + 10 很给力!

查看全部评分

回复

使用道具 举报

发表于 2014-9-11 14:34 | 显示全部楼层
本帖最后由 su45 于 2014-9-11 14:39 编辑

对,咱也正想说,一句就完成了

Selection.Borders.LineStyle = 1


评分

参与人数 1 +8 金币 +15 收起 理由
suye1010 + 8 + 15 赞一个!

查看全部评分

回复

使用道具 举报

发表于 2014-9-11 14:43 | 显示全部楼层
Borders Collection
A collection of four Border objects that represent the four borders of a Range or Style object.
Remarks


Use the Borders property to return the Borders collection, which contains all four borders.

You can set border properties for an individual border only with Range and Style objects. Other bordered objects, such as error bars and series lines, have a border that’s treated as a single entity, regardless of how many sides it has. For these objects, you must return and set properties for the entire border as a unit. For more information, see the Border object.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-5 22:34 , Processed in 0.798384 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表