自学内容网 自学内容网

自学VBA 设置单元格&文字格式 笔记

一.设定对应单元格对应需要显示的格式

Cells(1, 1).Font.Size = 18     '字体大小
Cells(1, 2).Font.Color = RGB(255, 0, 0) '字体颜色
Cells(1, 3).Font.Name = "黑体" '字体类型
Cells(1, 4).Font.Italic = True '字体斜体
Cells(1, 5).Font.FontStyle = "BOLD" '字体粗体
Cells(1, 6).Interior.Color = RGB(255, 0, 100) '背景颜色
Cells(1, 7).HorizontalAlignment = Excel.xlLeft '左对齐
Cells(1, 8).HorizontalAlignment = Excel.xlRight '右对齐
Cells(1, 9).HorizontalAlignment = Excel.xlCenter '居中对齐
Cells(1, 10).VerticalAlignment = xlVAlignCenter  '垂直居中
Cells(1, 11).VerticalAlignment = xlBottom  '置于底部
Cells(1, 12).VerticalAlignment = xlTop  '置于头部

二.设定对应位置初始化

Sub 初始化数据()
'
' 初始化数据 宏
    Range("A2").Select
    Selection.Copy
    Range("A1:L1").Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
End Sub

指定表单控件

视频演示:

测试VBA

格式有点多 写了点比较常用的


原文地址:https://blog.csdn.net/qq_48677456/article/details/138911466

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!