首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Word或WPS中批量设置表格样式的宏

Word或WPS中批量设置表格样式的宏

作者头像
软件测试大叔
发布2026-04-22 15:03:25
发布2026-04-22 15:03:25
1800
举报

在编写word文档的过程中,有时候会使用很多的表格,执行如下宏,批量设置全部表格的样式

代码语言:javascript
复制
Sub 批量设置表格样式()
'
' 批量设置表格样式 Macro
'
 
On Error Resume Next
 
Dim t As Table
 
For Each t In ActiveDocument.Tables
 
't.AutoFitBehavior (wdAutoFitContent) '根据内容自动调整表格
't.AutoFitBehavior (wdAutoFitWindow)  '根据窗口自动调整表格
t.AutoFitBehavior (wdAutoFitFixed) '固定列宽
 
 
 
t.Select
 
Selection.Cells.DistributeWidth
 
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
 
Selection.Columns(1).PreferredWidth = CentimetersToPoints(2.5) '第1列宽度值(单位:厘米),可自行修改
 
't.Rows.First.Select
'Selection.Font.Bold = -1 '首行字体加粗 0 不加粗
't.Rows.First.Cells.Shading.BackgroundPatternColor = wdColorWhite '首行背景色

t.Columns.First.Select
Selection.Font.Bold = -1 '首列字体加粗
t.Columns.First.Cells.Shading.BackgroundPatternColor = wdColorGray30 '首列背景色

 
Next
 
Selection.HomeKey Unit:=wdStory
End Sub
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-07-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档