'2楼的代码是针对文字的,不知道您的文档中是否还有其他什么对象.内容丢失不在于selection还是range,我现在将代码修改了一下,请楼主看看运行是否还有问题.如果还有问题的话,我想您最好能把原文件上传.以便分析,如果您的文件需要保密的话,可以将里面的文字修改后上传. Sub CreatDoc() Dim myRange As Range, int_Temp As Integer, str_Temp As String Dim ActiveDoc As Document, Doc_Temp As Document, ActPath As String Set ActiveDoc = ActiveDocument ActiveDoc.Characters.Last.InsertAfter Chr(13) & Chr(13) '为了得到全部要查找的结果,在文档最后加两个空段 ActPath = ActiveDoc.Path '获得文档路径 Set myRange = ActiveDoc.Content With myRange.Find .ClearFormatting .Text = "[!^13]*^13^13^13" .Forward = True .Format = False .Wrap = wdFindStop .MatchWildcards = True End With Do While myRange.Find.Execute int_Temp = int_Temp + 1 myRange.Copy Set Doc_Temp = Documents.Add If (int_Temp Mod 2) = 1 Then '有产品号码 str_Temp = Left(myRange.Paragraphs(1).Range.Text, myRange.Paragraphs(1).Range.Characters.Count - 1) On Error Resume Next MkDir ActPath & "\" & str_Temp & "\" Doc_Temp.Content.Paste Doc_Temp.Paragraphs(1).Range.Delete Doc_Temp.SaveAs ActPath & "\" & str_Temp & "\" & "产品概说" Doc_Temp.Close Else '无产品号码 Doc_Temp.Content.Paste Doc_Temp.SaveAs ActPath & "\" & str_Temp & "\" & "产品细述" Doc_Temp.Close End If Loop End Sub
[此贴子已经被作者于2007-5-15 14:19:16编辑过] |