VBA宏將文件分成多個子文件
子UpdateDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdDoc As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With wdDoc
'Call your other macro or insert its code here
'BreakOnSection
wdDoc.Activate
ActiveDocument.ActiveWindow.View.Type = wdOutlineView
Selection.WholeStory
Selection.Copy
ActiveDocument.Subdocuments.AddFromRange Range:=Selection.Range
ActiveDocument.SaveAs "C:\Data\Split\" & ActiveDocument.Name
ActiveDocument.Close SaveChanges:=True
End With
strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0,
"Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
我的僱主需要相當多的doc和docx修改。問題是兩者的解決方案都非常困難。在docx中,最好的辦法是將文檔解壓縮爲一個zip文件,然後您可以使用裏面的XML文件進行播放。您可以使用樣式或自定義樣式知道何時分割文檔或讓用戶添加一些自定義標籤。不幸的是,優雅的解決方案非常困難。 – 2010-02-18 22:30:35
對,我絕對不認爲自動化解決方案是可行的。如果用戶可以對捲進行標記,然後根據上傳之前標記的內容進行分割。 – Holograham 2010-02-18 22:45:49