|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
* 楼主,请打开文章后,用我的《公文自动排版》宏排版,然后应用下面的宏。
* 请复制代码后粘贴到新建文档中,再全选——复制——粘贴到 VBE 中使用,否则可能有乱码。
- Sub a0001_FillTextToTable()
- Dim doc As Document, i As Paragraph, c As Cell
- Set doc = ActiveDocument
- 'delete blank lines
- For Each i In doc.Paragraphs
- With i.Range
- If Asc(.Text) = 13 Then .Delete
- End With
- Next
- 'add two-full-spaces to per-line
- For Each i In doc.Paragraphs
- With i.Range
- With .ParagraphFormat
- If .CharacterUnitFirstLineIndent <> 0 Then
- .CharacterUnitFirstLineIndent = 0
- If .FirstLineIndent <> 0 Then
- .FirstLineIndent = 0
- .Parent.InsertBefore Text:=Chr(-24159) & Chr(-24159)
- End If
- End If
- End With
- End With
- Next
- 'add Enter-Symbol
- With Selection
- .HomeKey 6
- Do
- .EndKey
- If .End = doc.Content.End - 1 Then Exit Do
- If Asc(.Text) = 13 Then
- .MoveRight
- Else
- .TypeParagraph
- End If
- Loop
- 'text to table
- .WholeStory
- .ConvertToTable Separator:=wdSeparateByParagraphs, NumColumns:=1, _
- AutoFitBehavior:=wdAutoFitFixed
- .Tables(1).Style = "网格型"
- With .ParagraphFormat
- .LineUnitBefore = 0
- .LineUnitAfter = 0
- .SpaceBefore = 0
- .SpaceAfter = 0
- .LineSpacingRule = wdLineSpaceSingle
- End With
- .HomeKey 6
- End With
- 'distribute
- With doc.Tables(1)
- .Rows.Height = CentimetersToPoints(1.2)
- .Range.ParagraphFormat.Alignment = wdAlignParagraphJustify
- .Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
- For Each c In .Range.Cells
- With c.Range
- If .Characters.Count > 24 Then .ParagraphFormat.Alignment = wdAlignParagraphDistribute
- End With
- Next
- End With
- MsgBox "Complete!", 0 + 48
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|