vba 如何在单元格的一侧应用粗边框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28684330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 06:20:23  来源:igfitidea点击:

How do I apply a thick border to one side of cell

excelvba

提问by Jmel93

I wanted to know how to apply say a thick right border to all selected cells on Excel, preferably using a shortcut. I tried recording a macro and then applying a thick border and erasing the top, bottom and left cells, but that just meant only the top cell had the right border, and the rest of the selection had left and right borders.

我想知道如何对 Excel 上的所有选定单元格应用较粗的右边框,最好使用快捷方式。我尝试录制一个宏,然后应用粗边框并擦除顶部、底部和左侧的单元格,但这只是意味着只有顶部的单元格具有右边框,其余的选择具有左右边框。

I only just discovered macros on excel so if there's a code I need to enter, if you wouldn't mind telling me what to do before and after I enter the code in order for it to work, that would be great.

我只是在 excel 上发现了宏,所以如果我需要输入代码,如果您不介意告诉我在输入代码之前和之后要做什么以使其正常工作,那就太好了。

回答by Perposterer

Something like this should work...

像这样的东西应该工作......

Dim MyRange as range
MyRange = activesheet.range("C1:C14")
MyRange.Borders(xlEdgeRight).LineStyle = xlContinuous
MyRange.Borders(xlEdgeRight).Weight = xlThick 
MyRange.Borders(xlInsideVertical).LineStyle = xlContinuous
MyRange.Borders(xlInsideVertical).Weight = xlThick 

Selection can be used in place of the MyRange Range object

可以使用选择代替 MyRange Range 对象

Selection.Borders(xlEdgeRight).LineStyle = xlContinuous
Selection.Borders(xlEdgeRight).Weight = xlThick 
Selection.Borders(xlInsideVertical).LineStyle = xlContinuous
Selection.Borders(xlInsideVertical).Weight = xlThick 

Other line weight constants...

其他线宽常量...

    'other weight constants...
    'xlHairline 
    'xlMedium 
    'xlThick 
    'xlThin 

回答by Dan Donoghue

This should work:

这应该有效:

Sub ThickLeftBorders()
'Clear existing borders
Selection.Borders.LineStyle = xlNone
'Apply left border
With Selection.Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .Weight = xlThick
End With
'Apply inside border (Left on all other columns in range)
With Selection.Borders(xlInsideVertical)
    .LineStyle = xlContinuous
    .Weight = xlThick
End With
End Sub