'请参考: Sub newFile() Dim myPath As String, myShape As Shape, myRange As Range Dim txt_Doc As Document, txt_Path With Application.FileDialog(msoFileDialogFilePicker) .Title = "请选择被处理的txt文件" .AllowMultiSelect = True .Filters.Clear .Filters.Add "文本文件", "*.txt" If .Show = -1 Then For Each txt_Path In .SelectedItems Set txt_Doc = Documents.Open(FileName:=txt_Path) With txt_Doc.Paragraphs(1).Range.Font .Name = "黑体" .Size = 36 .Color = wdColorRed .Parent.ParagraphFormat.Alignment = wdAlignParagraphCenter End With txt_Doc.Paragraphs(2).Range.Delete '删除文本文件中的空白第二段 With txt_Doc.Paragraphs(2).Range.Font '删除空白段后,第3段变为第2段 .Name = "仿宋_GB2312" .Size = 15 .Parent.ParagraphFormat.Alignment = wdAlignParagraphCenter End With txt_Doc.Paragraphs(3).Range.InsertAfter Chr(13) '第三段后加一个空段 Set myShape = txt_Doc.Shapes.AddLine(0, 10, 420, 10, txt_Doc.Paragraphs(3).Range) With myShape .Line.Weight = 3# .Line.DashStyle = msoLineSolid .Line.Style = msoLineSingle .Line.Transparency = 0# .Line.Visible = msoTrue .Line.ForeColor.RGB = RGB(255, 0, 0) .Line.BackColor.RGB = RGB(255, 255, 255) .Line.BeginArrowheadLength = msoArrowheadLengthMedium .Line.BeginArrowheadWidth = msoArrowheadWidthMedium .Line.BeginArrowheadStyle = msoArrowheadNone .Line.EndArrowheadLength = msoArrowheadLengthMedium .Line.EndArrowheadWidth = msoArrowheadWidthMedium .Line.EndArrowheadStyle = msoArrowheadNone End With Set myRange = txt_Doc.Range(txt_Doc.Paragraphs(3).Range.Start, txt_Doc.Content.End) With myRange .Font.Name = "仿宋_GB2312" .Font.Size = 16 .ParagraphFormat.CharacterUnitFirstLineIndent = 2 End With txt_Doc.Sections(1).Headers(1).Range.Style = "正文" '除页眉横线 txt_Doc.Sections(1).Footers(1).PageNumbers.Add PageNumberAlignment:= _ wdAlignPageNumberCenter, FirstPage:=True On Error Resume Next MkDir txt_Doc.Path & "\New" txt_Doc.SaveAs txt_Doc.Path & "\New\" & Left(txt_Doc.Name, Len(txt_Doc.Name) - 3) & "doc", wdFormatDocument txt_Doc.Close Next Else Exit Sub End If End With End Sub |