咔片PPT · AI自动生成演示文稿,模板丰富、排版精美 讯飞智文 · 一键生成PPT和Word,高效应对学习与办公

收录一点常用的调整格式的语句,免得总要用宏录制来查看语句怎么写。

With Range("A1:A10") .CurrentRegion.HorizontalAlignment = xlCenter ' 水平居中 .HorizontalAlignment = xlDistributed ' 水平方向 分散对齐(垂直方向没有) .IndentLevel = 1 ’分散对齐的缩进,缩进1个字符位 .VerticalAlignment = xlCenter ' 垂直居中 .WrapText = True '开启自动换行 .Font.Name = "微软雅黑" .Font.FontStyle = "加粗" .Font.ColorIndex = 3 '设定单元格内字体颜色 .Interior.ColorIndex = 3 '设定单元格背景颜色 //绘制边框线: .Borders.Weight = xlThin '添加单元格边框线(细线) .Borders(xlEdgeBottom).Weight = xlMedium '添加底边框线,框线中号粗线 //xlEdgeTop 上边框线,xlEdgeLeft 左边框线,xlEdgeRight 右边框线 Range.Borders(xlEdgeBottom).Color = -16776961 '-16776961是系统自带的一种红色 .Borders(xlEdgeBottom).Color =RGB(198,224,180) //RGB(198,224,180) 淡绿;RGB(155,194,230) 淡蓝;RGB(237,125,49) 淡橙 .Entirecolumn.Autofit '自动调整单元格所在列的宽度,使用中发现与“水平居中”有点冲突 // 当前列 Entirecolumn 当前行 Entirerow .ColumnWidth = 50 '设定rng单元格所在列的列宽 .RowHeight = 34.5 '设定rng单元格所在行的行高 // .Width;.Height 为单元格的宽与高,为只读属性,不能赋值。 End With

列宽、行高的值是以字符的宽高来衡量的,不是像素值(也不是Wps中的厘米)。也无参数改变以像素值来代替,只能靠手感。

Columns(rng.Column).ColumnWidth;Rows(rng.Row).RowHeight也能用来调整,列宽行高。但Columns(1)只能用数字参数,表示某一列,多列不能写为Columns(“1:4”),只能写成Columns(“A:D”)。建议表述为range(Cells(变量1,变量2),Cells(变量3,变量4)).Entirecolumn.ColumnWidth=值。

单元格底纹的相关设置:

Cells.Interior.Pattern = 1 '取消了掉表格默认的行列分隔线,效果见下图

Range().Interior.Pattern = xlGray25 '单元格底纹的图案 名称

Range().Interior.PatternColor = RGB(155, 194, 230) '单元格底纹的图案的颜色

注:必须先有图案,才能设置颜色,否则没有显示效果 。

得到某个单元格颜色的RGB值。 y =range("D2").interior.color '先调好单元格的背景色 R = y mod 256 G = y 256 mod 256 B = y 256 ^2 mod 256 Range("B2").Interior.Color = RGB(R, G, B) '将别的单元格义底色改成此色