一、如何用word vba,根据特定字符保存文件
Sub test() Dim Doc As Document On Error Resume Next For i = 1 To ThisDocument.Paragraphs.Count txt = ThisDocument.Paragraphs(i).Range.Text z = Split(Split(txt, "【")(1), "】")(0) If Err.Number = 0 Then rng = rng & i & " " Else Err.Clear Next z = Split(rng, " ") z(UBound(z)) = ThisDocument.Paragraphs.Count + 1 On Error GoTo 0 For j = 0 To UBound(z) - 1 Set Doc = Documents.Add Set rngParagraphs = ThisDocument.Range(Start:=ThisDocument.Paragraphs(z(j)).Range.Start, _ End:=ThisDocument.Paragraphs(z(j + 1) - 1).Range.End) rngParagraphs.Select Selection.Copy Doc.Range.Paste Doc.SaveAs "D:\" & Replace(ThisDocument.Paragraphs(z(j)).Range.Text, Chr(13), "") & ".Doc" Doc.Close True NextEnd Sub。
二、如何用word vba,根据特定字符保存文件
Sub test()
Dim Doc As Document
On Error Resume Next
For i = 1 To ThisDocument.Paragraphs.Count
txt = ThisDocument.Paragraphs(i).Range.Text
z = Split(Split(txt, "【")(1), "】")(0)
If Err.Number = 0 Then rng = rng & i & " " Else Err.Clear
Next
z = Split(rng, " ")
z(UBound(z)) = ThisDocument.Paragraphs.Count + 1
On Error GoTo 0
For j = 0 To UBound(z) - 1
Set Doc = Documents.Add
Set rngParagraphs = ThisDocument.Range(Start:=ThisDocument.Paragraphs(z(j)).Range.Start, _
End:=ThisDocument.Paragraphs(z(j + 1) - 1).Range.End)
rngParagraphs.Select
Selection.Copy
Doc.Range.Paste
Doc.SaveAs "D:\" & Replace(ThisDocument.Paragraphs(z(j)).Range.Text, Chr(13), "") & ".Doc"
Doc.Close True
Next
End Sub
转载请注明出处51数据库 » wordvba特殊字符