|
代码:
Word代码:
- Sub pCopy(control As IRibbonControl)
- Dim p$, f$, w As Object
- Application.Visible = False
- Set w = ActiveDocument
- p = w.Path & ""
- Selection.WholeStory
- Selection.Delete Unit:=wdCharacter, count:=1
- f = Dir(p & "*.doc")
- Do While f <> ""
- If f <> w.Name Then
- With Documents.Open(p & f)
- Selection.WholeStory
- Selection.Copy
- w.Activate
- Selection.PasteAndFormat (wdPasteDefault)
- .Close
- End With
- End If
- f = Dir
- Loop
- Application.Visible = True
- End Sub
- Sub SplitPagesAsDocuments(control As IRibbonControl)
- Dim oSrcDoc As Document, oNewDoc As Document
- Dim strSrcName As String, strNewName As String
- Dim oRange As Range
- Dim nIndex As Integer
- Dim fso As Object
- On Error Resume Next
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set oSrcDoc = ActiveDocument
- Set oRange = oSrcDoc.Content
- oRange.Collapse wdCollapseStart
- oRange.Select
- For nIndex = 1 To ActiveDocument.Content.Information(wdNumberOfPagesInDocument)
- oSrcDoc.Bookmarks("\page").Range.Copy
- oSrcDoc.Windows(1).Activate
- Application.Browser.Target = wdBrowsePage
- Application.Browser.Next
- strSrcName = oSrcDoc.FullName
- strNewName = fso.BuildPath(fso.GetParentFolderName(strSrcName), _
- fso.GetBaseName(strSrcName) & "_" & nIndex & "." & _
- fso.GetExtensionName(strSrcName))
- Set oNewDoc = Documents.Add
- Selection.Paste
- oNewDoc.SaveAs Mid(strNewName, 1, Len(strNewName) - 1)
- oNewDoc.Close False
- Next
- Set oNewDoc = Nothing
- Set oRange = Nothing
- Set oSrcDoc = Nothing
- Set fso = Nothing
- MsgBox "结束!"
- End Sub
复制代码 |
|