P
periodic
I have read that master documents are not good. But for now I want to give it
try but still be on the safe side. By writing some VBA code to take a number
of files make a subfolder, copy all relevant files there and then create a
master document there. So it does not matter if the master document corrupts
some files since they are just copies of the original anyway. Plus I can make
different editions of the book I am working on putting together. The editions
must have some different formating and so on. Anyway I have gotten folder and
file handling to work fine for me. Although when I try to run the following
code.
Sub makeEdition(currPath As String, dirName As String, ByRef filesToCopy As
Collection)
makeDirAndFillIn currPath:=currPath, dirName:=dirName,
filesToCopy:=filesToCopy
ChDir path:=currPath
Documents.Add Template:=currPath & "\Chapter-template.dot"
Dim masterName As String
masterName = currPath & "\" & dirName & "\master.doc"
ActiveDocument.SaveAs fileName:=masterName,
FileFormat:=wdFormatDocument, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False,
SaveFormsData:=False, _
SaveAsAOCELetter:=False
Dim masterDoc As Document
Dim masterDocRange As Range
Set masterDoc = Documents("master.doc")
Set masterDocRange = masterDoc.Range
masterDocRange.Collapse direction:=wdCollapseStart
ActiveWindow.ActivePane.View.Type = wdMasterView
Dim subDocName As String
Dim subDocPath As String
subDocPath = currPath & "\" & dirName & "\"
ChangeFileOpenDirectory path:=subDocPath
For i = 1 To filesToCopy.count
subDocName = filesToCopy(i)
masterDocRange.Subdocuments.AddFromFile name:=subDocName,
ConfirmConversions:=False, ReadOnly:=False, Revert:=True
Next i
masterDoc.Close
End Sub
It it the last for loop that is the problem. As soon as I try to add a sub
document. Word hangs and stops responding and I have to kill it from the task
manager.
Does anyone have any ideas why this does not work or this a bug in word?
I think I am going to use the INCLUDETEXT field instead. But I can't help
wondering what is wrong with my code.
try but still be on the safe side. By writing some VBA code to take a number
of files make a subfolder, copy all relevant files there and then create a
master document there. So it does not matter if the master document corrupts
some files since they are just copies of the original anyway. Plus I can make
different editions of the book I am working on putting together. The editions
must have some different formating and so on. Anyway I have gotten folder and
file handling to work fine for me. Although when I try to run the following
code.
Sub makeEdition(currPath As String, dirName As String, ByRef filesToCopy As
Collection)
makeDirAndFillIn currPath:=currPath, dirName:=dirName,
filesToCopy:=filesToCopy
ChDir path:=currPath
Documents.Add Template:=currPath & "\Chapter-template.dot"
Dim masterName As String
masterName = currPath & "\" & dirName & "\master.doc"
ActiveDocument.SaveAs fileName:=masterName,
FileFormat:=wdFormatDocument, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False,
SaveFormsData:=False, _
SaveAsAOCELetter:=False
Dim masterDoc As Document
Dim masterDocRange As Range
Set masterDoc = Documents("master.doc")
Set masterDocRange = masterDoc.Range
masterDocRange.Collapse direction:=wdCollapseStart
ActiveWindow.ActivePane.View.Type = wdMasterView
Dim subDocName As String
Dim subDocPath As String
subDocPath = currPath & "\" & dirName & "\"
ChangeFileOpenDirectory path:=subDocPath
For i = 1 To filesToCopy.count
subDocName = filesToCopy(i)
masterDocRange.Subdocuments.AddFromFile name:=subDocName,
ConfirmConversions:=False, ReadOnly:=False, Revert:=True
Next i
masterDoc.Close
End Sub
It it the last for loop that is the problem. As soon as I try to add a sub
document. Word hangs and stops responding and I have to kill it from the task
manager.
Does anyone have any ideas why this does not work or this a bug in word?
I think I am going to use the INCLUDETEXT field instead. But I can't help
wondering what is wrong with my code.