|
本帖最后由 413191246se 于 2012-12-27 11:21 编辑
声明一下:虽然热心无限,但因水平问题,只能算完成了一半或多一点吧,感觉复杂,似应用到Range的问题,要想完美解决,须请sylun大侠解决,仅为楼主提供一定参考吧!(光标焦点位于原始文档后应用,可以设置本宏为热键 F4,方便应用。另,楼主不必着急,可等待高手进一步完善。)
[code=vb]Sub 提取文字()
Dim y As String
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Text = "事实与理由"
Selection.Find.Execute
Selection.EndKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Paragraphs(1).Range.Select
y = Selection.Text
y = Left(y, Len(y) - 1)
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Text = "甲方请求"
Selection.Find.Execute
Selection.HomeKey Unit:=wdLine
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.Copy
' 新建文档
Documents.Add DocumentType:=wdNewBlankDocument
' 生成目标文档
Selection.TypeText Text:="争议解决方案草稿" & vbCr
ActiveDocument.Paragraphs(2).Range.Delete
Selection.PasteAndFormat (wdPasteDefault)
Selection.TypeText Text:=vbCr & "经研究,XXXXXXXXX存在甲种纠纷,简介如下。" & vbCr & "甲方声称,"
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Text = "甲方声称,"
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=y & "纠纷因此产生,建议如下协调:" & vbCr & "一、乙方ZZZZZZZZZZ。" & vbCr & "上述协议,不违反法律规定,希望双方自愿遵守。"
ActiveDocument.Content.Find.Execute FindText:="争议简介", ReplaceWith:="", Replace:=wdReplaceAll
' 简单排版
Selection.WholeStory
Selection.ClearFormatting
Selection.ClearFormatting
Selection.Font.Size = 14
Selection.ParagraphFormat.LineSpacing = LinesToPoints(1.25)
Selection.ParagraphFormat.CharacterUnitFirstLineIndent = 2
' 设置标题一
With ActiveDocument
.Paragraphs(1).Range.InsertParagraphBefore
.Paragraphs(2).Range.InsertParagraphAfter
With .Range(Start:=0, End:=.Paragraphs(3).Range.End)
.Style = ActiveDocument.Styles(wdStyleHeading1)
With .ParagraphFormat
.SpaceBefore = 0
.SpaceAfter = 0
.LineSpacing = LinesToPoints(1.15)
.Alignment = wdAlignParagraphCenter
End With
End With
.Paragraphs(1).Range.Font.Size = 22
.Paragraphs(3).Range.Font.Size = 18
End With
With Selection.Font
.Kerning = 0
.DisableCharacterSpaceGrid = True
End With
With Selection.ParagraphFormat
.AutoAdjustRightIndent = False
.DisableLineHeightGrid = True
End With
ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitBestFit
Selection.HomeKey Unit:=wdStory
' 插入表格
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:= _
4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "网格型" Then
.Style = "网格型"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.TypeText Text:="拟稿人"
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="拟稿时间"
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="核稿意见"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="打印 份"
Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend
Selection.Cells.Merge
Selection.Tables(1).Select
Selection.Font.Size = 12
Selection.ParagraphFormat.Space1
Selection.SelectCell
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter
Selection.Rows(1).Height = CentimetersToPoints(1)
Selection.Rows(2).Height = CentimetersToPoints(2)
Selection.Rows(2).Cells(2).Select
Selection.TypeParagraph
Selection.TypeParagraph
Selection.Tables(1).Select
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Tables(1).Select
Selection.Font.Bold = False
Selection.HomeKey Unit:=wdStory
End Sub[/code] |
|