利用EXCEL中的宏命令自动排版
在工作中,我们希望将自己制作的所有EXCEL工作簿中的工作表采用统一格式,如字体统一,字号统一。有没有简单的办法来实现它呢?事实上,我们可以采用宏命令来实现它。即事先根据自己或是工作中的排版习惯将排版要求事实录制宏命令,然后执行宏命令即可。
比如,我们的排版要求如下:
以A1单元格作为表格名称,采用华宋中文,16号字,加粗显示;其它单元格宋体,10号字,单元格根据单元内容自动调整行高与列宽。其格式如下:
我们可以通过【开发工具】/〖录制宏〗让系统自动录制如下宏命令。大家可以将之复制粘贴到【开发工具】/〖Visul Basic〗VBA模块中。
然后将再执行【开发工具】/〖宏〗/ EXCEL格式统一排版,即可完成EXCEL自动排版。效果如上图。
参考资料:钭志斌,《EXCEL在财务中的应用实训》,高等教育出版社
其录制的命令如下:
'' EXCEL格式统一排版 Macro
'
'
Cells.Select
With Selection.Font
.Name = "宋体"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontMinor
End With
Selection.Rows.AutoFit
Selection.Columns.AutoFit
Selection.Rows.AutoFit
Selection.Columns.AutoFit
Range("A1").Select
With Selection.Font
.Name = "华文中宋"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With Selection.Font
.Name = "华文中宋"
.Size = 16
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Selection.Font.Bold = True
Range("A4").Select
End Sub
利用EXCEL中的宏命令自动排版
评论
4 views