首页 > 其他分享 >VBA-Excel边框加颜色

VBA-Excel边框加颜色

时间:2022-12-08 13:55:25浏览次数:42  
标签:TintAndShade VBA Selection End Excel 边框 Range Borders LineStyle


Sub font_sty(Rng As Range)
Rng.Select
Selection.Font.Bold = True
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.349986266670736
.PatternTintAndShade = 0
End With
End Sub
vba设置单元格边框,以下是设置给定单元格边框,参数是Range对象

Sub sty_sig(Rng As Range)
Rng.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 Sub

对这两个方法(片段)进行调用

我们使用《如何系列(二)》中的例子,最后增加两个call 分别call设置单元格字体格式,和设置单元格边框

Sub sqltest()
Dim Spath As String
Spath = ThisWorkbook.Path & "\pbxtest.xlsx"
Set adConn = New ADODB.Connection
'
adConn.Open "provider=Microsoft.ACE.OLEDB.12.0;extended properties=excel 12.0;Extended Properties='Excel 8.0;HDR=Yes;IMEX=1';data source=" & Spath & ""
Set rs = adConn.Execute("Select 编号,测试环境,测试项目 From [sheet1$a1:j35] ")
'
sht_name = "sheet3"
Set sht = ThisWorkbook.Worksheets(sht_name)
'
For i = 1 To rs.Fields.Count Step 1
sht.Range("A1").Offset(0, i - 1) = rs.Fields(i - 1).Name '
Next i
'
sht.Range("A2").CopyFromRecordset rs
sht.Cells.EntireColumn.AutoFit
Call sty_sig(Range(Cells(1, 1), Cells(13, 3)))
Call font_sty(Range(Cells(1, 1), Cells(1, 3)))
End Sub

结果:

 

之前的:


 
原文链接:https://blog.csdn.net/monkeyzh123/article/details/88976921

标签:TintAndShade,VBA,Selection,End,Excel,边框,Range,Borders,LineStyle
From: https://www.cnblogs.com/Insist-Y/p/16965879.html

相关文章

  • 爬取的数据存入csv文件-用excel直接打开乱码解决方法
    如图所示:解决方法:用记事本打开另存为,编码格式为ansicsv部分源码......
  • vba进度条制作
    Sub进度条()DimrowTotalAsIntegerrowTotal=100Fori=1TorowTotalStep1prgramBarShow.Show0prgramBarShow.lblProgress.Wi......
  • 用vba把excel文件发布转化为pdf格式文件
    SubPDF()DimasyAsWorksheetDimspathAsStringspath=Excel.ThisWorkbook.PathForEachasyInExcel.ThisWorkbook.WorksheetssName=spath&"\"&as......
  • vba-窗体间传值
    1,模块加PublicxOBjAsNewMSForms.DataObject2,第一个窗体PrivateSubCommandButton1_Click()IfMe.TextBox1.Value=""ThenExitSubWithxOBj......
  • vba-命名规范
    给用户窗体和控件起一个具有描述性且分类清楚的名字,是一个习惯。最好在每类控件名前加一个前缀来代表该控件的类型,例如,frm代表用户窗体,opt代表选项按钮,等等。这样,将会使代......
  • VBA学习笔记3-数据结构类型SortedList
    https://blog.csdn.net/lyfegf/article/details/103750912?spm=1001.2101.3001.6650.6&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-......
  • VBA-语法-Type结构体
    VBA中结构体不能定义在函数或者过程中,要定义在模块中,否则会提示无效内部过程,或者类型未定义定义:TypePersonpNameAsStringpAgeAsByteEndType使用:Di......
  • spring boot中Excel文件下载踩坑大全
    项目场景:Springboot文件下载调用接口下载springboot工程的resources目录下的excel模板文件,非常常见的一个文件下载功能,但是却容易遇到很多坑,下面总结记录下。问题一:下载的......
  • CSS3旋转流动的彩色边框特效
     效果图如图所示:  <divclass='box'>你好</div><stylelang='scss'>.box{position:relative;border-radius:10px;......
  • Excel VLOOKUP 函数的使用
    需要注意的几个地方:IFERROR,第一个参数,是需要判断的值VLOOKUP,第二个参数,匹配的区域,第一列,必须是匹配的列。比如:第一个参数是订单号,那么第二个参数的那个区域的第一列......