|
* 楼主,你好!刚学 VBA 如果使用的是 Word2003 的话,强烈建议反复研读《Microsoft Office Word 2003 Visual Basic 参考》,即:微软官方 Word2003VBA 帮助这个文档,它的文件名是:VBAWD10.CHM,具体位置:C:\Program Files\Microsoft Office\OFFICE11\2052 文件夹中;或搜索网络也可得到。
* 关于你提出的问题,我有一个解决方案,供你参考,另外,你看没看到我的帖子《Word2003VBA通用模板宏》,如果你也使用 Word2003 版本,建议下载我的宏代码,会帮助到你的。
* 楼主,如果你使用的是 Word2003/2007,请按 ALT+F11 复制本代码到你的 VBE 中,按 F8 键可逐语句调试。
* 下面是 Word2003VBA 公文自动排版(一键)部分代码,请新建包含文本和表格的文档试用之:
- Sub 公文()
- Dim doc As Document, t As Table, j As Long, k As Long
- Set doc = ActiveDocument
- ActiveWindow.View.Type = wdPrintView
- With doc
- With .Content.Find
- .Execute "^13", , , , , , , , , "^p", 2
- .Execute "^11", , , , , , , , , "^p", 2
- .Parent.ListFormat.ConvertNumbersToText
- End With
- If .Tables.Count = 0 Then
- .Select
- 正文样式
- Else
- '取消环绕
- For Each t In .Tables
- With t.Range
- With .Rows
- .WrapAroundText = False
- .Alignment = wdAlignRowCenter
- End With
- .Font.Name = "仿宋_GB2312"
- .Font.Color = wdColorPink
- End With
- Next
- '首表上方
- If .Paragraphs(1).Range.Information(wdWithInTable) = False Then
- .Range(Start:=0, End:=.Tables(1).Range.Start).Select
- 正文样式
- End If
- '表间循环
- k = .Tables.Count
- For j = 1 To k
- If j = k Then Exit For
- .Range(Start:=.Tables(j).Range.End, End:=.Tables(j + 1).Range.Start).Select
- 正文样式
- Next j
- '末表下方
- .Range(Start:=.Tables(k).Range.End, End:=.Content.End).Select
- 正文样式
- '表下加空
- For Each t In .Tables
- With t.Range.Next
- If Asc(.Text) <> 13 Then .InsertParagraphBefore: .MoveEnd 1, -1
- .Font.Size = 4
- End With
- Next
- End If
- End With
- Selection.HomeKey Unit:=wdStory
- End Sub
- Sub 正文样式()
- Dim i As Paragraph, r As Range
- With Selection
- .ClearFormatting
- CommandBars.FindControl(ID:=122).Execute
- CommandBars.FindControl(ID:=123).Execute
- With .Font
- .Name = "仿宋_GB2312"
- .Size = 16
- .Color = wdColorBlue
- .Kerning = 0
- .DisableCharacterSpaceGrid = True
- End With
- With .ParagraphFormat
- .LineSpacing = LinesToPoints(1.5)
- .CharacterUnitFirstLineIndent = 2
- .AutoAdjustRightIndent = False
- .DisableLineHeightGrid = True
- End With
- Set r = .Range
- For Each i In r.Paragraphs
- If Asc(i.Range) = 13 Then i.Range.Delete
- Next
- End With
- End Sub
复制代码 |
|