以下是引用konggs在2007-2-24 12:15:50的发言:不要格式的: Sub 中国() Dim astring As String Dim arr, arr1, Restring As String Const ConstChina = "中国" '定义常量 astring = ActiveDocument.Content '文档内容 arr = Split(astring, Chr(13)) '分列为数组 For Each arr1 In arr '每段中循环 If InStr(arr1, ConstChina) > 0 Then Restring = Restring & arr1 & Chr(13) End If Next Dim doc As Document '添加新文档 Set doc = Documents.Add doc.Content = Restring '内容添加到新文档 doc.Paragraphs.Last.Range.Delete '去掉最后一个回车 End Sub 孔兄,我在你基础上做了一个,顺便分享一下数组常用函数。 '* +++++++++++++++++++++++++++++ '* Created By SHOUROU@ExcelHome 2007-2-24 16:05:38 '仅测试于System: Windows NT Word: 11.0 Language: 2052 '№ 0167^The Code CopyIn [ThisDocument-ThisDocument]^' '* ----------------------------- Sub Example() '本例旨在说明如何使用数组中的三个常用函数:Split,Filter,Join Dim myString As String, NewDoc As Document Dim myArray() As String, TempArray() As String Const myText As String = "敏捷" myString = ThisDocument.Content.Text '取得文档内容 myArray = VBA.Split(myString, Chr(13)) '以"段落"标记为分隔符取得数组 TempArray = VBA.Filter(myArray, myText, True) '返回一个包含指定文本的数组,即筛选后符合条件的数组 Documents.Add.Content.Text = VBA.Join(TempArray, Chr(13)) '以"段落"标记为连接符将数组内容转换为文本字符串并写入空白文档 End Sub '----------------------
|