使用VB对word文档进行格式调整
来源:互联网 发布:淘宝订单险要求是什么 编辑:程序博客网 时间:2024/05/19 09:11
在word文档中,有时候会出现大量表格,在需要调整格式时,只能一个一个手动刷格式,这样不仅费时而且很费力。本人在写文档时,碰到这种情况,熬夜干活儿,太累。所以下定决心,抽点时间研究WORD中的宏编程。经过测试,基本上能批量改变word中的样式。下面附上本人研究VB代码,打开word中的宏。
操作方式:开发工具(如果没有,直接点击工具栏,右键,自定义工具,选择开发工具),如果有兴趣研究的话,可以采用录制宏的方式,查看其代码。
Sub Doc_tableUpdate()
'处理所有表格的Table,ActiveDocument.Tables.Count获取表格数
For i = 1 To ActiveDocument.Tables.Count
'定义为Table的第一行的颜色
ActiveDocument.Tables(i).Rows(1).Shading.ForegroundPatternColor = -570366209
'j用来控制行,m用来控制列,实现两个循环
For j = 2 To ActiveDocument.Tables(i).Rows.Count
For m = 1 To ActiveDocument.Tables(i).Columns.Count
ActiveDocument.Tables(i).Cell(j, m).Range.Bold = 0
'ActiveDocument.Tables(i).Cell(j, m).Range.Paragraphs.Format.Style
ActiveDocument.Tables(i).Cell(1, m).Range.Paragraphs.Alignment = wdAlignParagraphCenter
ActiveDocument.Tables(i).Cell(j, m).Range.Paragraphs.LeftIndent = -2
ActiveDocument.Tables(i).Cell(j, m).Range.Style.Font.Name = "宋体"
ActiveDocument.Tables(i).Cell(j, m).Range.Style.Font.Size = 12
Next m
Next j
Next i
End Sub
Sub editContent()
'
' 宏1 宏
'
'with为重新定义正文样式
With ActiveDocument.Styles("正文").Font
.NameFarEast = "黑体"
.NameAscii = "+西文正文"
.NameOther = "+西文正文"
.Name = "+西文正文"
.Size = 14
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Scaling = 100
.Kerning = 1
.Animation = wdAnimationNone
.DisableCharacterSpaceGrid = False
.EmphasisMark = wdEmphasisMarkNone
.Ligatures = wdLigaturesNone
.NumberSpacing = wdNumberSpacingDefault
.NumberForm = wdNumberFormDefault
.StylisticSet = wdStylisticSetDefault
.ContextualAlternates = 0
End With
With ActiveDocument.Styles("正文").ParagraphFormat
.LeftIndent = CentimetersToPoints(0)
.RightIndent = CentimetersToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpace1pt5
.Alignment = wdAlignParagraphJustify
.WidowControl = False
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = CentimetersToPoints(0.35)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 2
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
.AutoAdjustRightIndent = True
.DisableLineHeightGrid = False
.FarEastLineBreakControl = True
.WordWrap = True
.HangingPunctuation = True
.HalfWidthPunctuationOnTopOfLine = False
.AddSpaceBetweenFarEastAndAlpha = True
.AddSpaceBetweenFarEastAndDigit = True
.BaseLineAlignment = wdBaselineAlignAuto
End With
ActiveDocument.Styles("正文").NoSpaceBetweenParagraphsOfSameStyle = False
With ActiveDocument.Styles("正文")
.AutomaticallyUpdate = False
.BaseStyle = ""
.NextParagraphStyle = "正文"
End With
End Sub
Sub applyStyles()
'
' applyStyles 宏
'
'
Selection.Style = ActiveDocument.Styles("正文")
End Sub
Sub testApplyStyles()
'For i = 1 To ActiveDocument.Paragraphs.Count
'ActiveDocument为当前活动文档,Paragraphs为段落。该句含义为将文档所有正文使用样式正文,wdStyleNormal为正文默认,wdStyleHeading1为标题1,依此类推
ActiveDocument.Paragraphs.Style = ActiveDocument.Styles("正文")
'Next
' ActiveDocument.Styles("正文").NoSpaceBetweenParagraphsOfSameStyle = False
' With ActiveDocument.Styles("测试样式")
' .AutomaticallyUpdate = False
' .BaseStyle = ""
' .NextParagraphStyle = "测试样式"
' End With
End Sub
- 使用VB对word文档进行格式调整
- 使用vba进行Word文档的数学格式设置
- C# 中使用Word文档对图像进行操作
- 如何对word文档进行word加密
- 使用Java的POI进行Word文档的解析并生成XML格式文档
- C# 对Word文档进行处理
- VB调整Excel格式
- word 目录格式调整
- 使用FreeMarker导出固定格式word文档
- 使用maven管理jacob.jar对excel、word文档进行转换为html细节描述
- VB打开Word文档
- 如何把word与pdf等文档格式进行转换
- 根据规范文档所推荐:在 Eclipse 使用 formatter 对代码格式 进行规范。
- word mathtype 公式格式调整
- 使用POI对word文件进行读取
- Word中如何对文档进行简单加密
- ViKey加密狗对Word文档进行加密
- 使用宏对word中的图片批量调整大小
- 【IPC通信】基于管道的popen和pclose函数
- 正则表达式大全
- 如何在Eclipse中查看Android源代码
- 90.Examine the structure and data in the PRICE_LIST table:
- 关于Xutils框架出现无法访问HttpRequestBase 找不到org.apache.http.client.methods.HttpRequestBase解决方案
- 使用VB对word文档进行格式调整
- C库函数 - memset()
- css3图片滤镜
- android linux下编译问题
- Something I'll Referrence
- html 使用Ajax 实现多文件上传,并显示进度
- 布局中动态添加View
- 线程的4种状态
- Java — 面向对象