在Office精英俱乐部里有一个分页保存的宏代码,很是漂亮:可列为精华: Sub 分页保存() myPath = "D:\temp\" Selection.HomeKey Unit:=wdStory Set myRange = Selection.Range curpage = 0 Application.ScreenUpdating = False Do prepage = curpage pagenum = pagenum + 1 Set myRange = myRange.GoToNext(What:=wdGoToPage) curpage = myRange.Start endpage = myRange.Previous.Start If curpage = prepage Then _ endpage = ActiveDocument.Content.End ActiveDocument.Range(prepage, endpage).Copy With Documents.Add .Content.Paste .SaveAs myPath & "Page" & pagenum & ".doc" .Close End With If curpage = prepage Then Exit Do Loop Application.ScreenUpdating = True End Sub 但有这样一个问题,我这个文件怎么不能分开,请教高手,怎么不行?
S9vV5zqw.rar
(14.58 KB, 下载次数: 87)
下面是本论坛守柔兄的代码,粘贴于活动文档中(即你的主文档中)的“THISDOCUMENT”模块中: Sub SaveAsPage() Dim PageCount As Integer, StartRange As Long, EndRange As Long, MyRange As Range, Fn As String, MyDoc As Document On Error Resume Next PageCount = Selection.Information(wdNumberOfPagesInDocument) Range(0, 0).Select '将光标移至文档起点 For i = 1 To PageCount '设置循环次数 StartRange = Selection.Start '取得该页的第一个字符位置 Selection.EndKey Unit:=wdLine '将光标移动到该页首行的最后位置 Fn = i & ActiveDocument.Name '-1的目的是防止该页首行含有段落标记,导致出错. If i = PageCount Then '如果循环到达最后一页 EndRange = ActiveDocument.Content.End '将文档最后位置赋值于EndRange Else Selection.GoToNext (wdGoToPage) '否则,将下一页的起始位置赋值于EndRange(等同于本页的最后位置) EndRange = Selection.Start End If Set MyRange = Range(StartRange, EndRange) '将本页中的内容进行复制 MyRange.Copy Set MyDoc = Documents.Add '新建一空白文档 MyDoc.Range(0, 0).Paste '在文档开始处粘贴 MyDoc.SaveAs FileName:=Fn '保存文档名 MyDoc.Close '关闭文档 Next End Sub
[此贴子已经被konggs于2008-8-23 10:26:50编辑过] |