crowfan
07-31-2007, 07:24 AM
Hello all,
I am trying to consolidate all of the files in a folder into one file. Using the example from the Word VBA help file (under the "InsertFile" entry), I have it working the way that I want. Here it is:
Sub testmacro()
Dim myName As String
Dim myPath As String
Documents.Add Template:="myTemplate.DOT"
Selection.WholeStory
Selection.Collapse Direction:=wdCollapseEnd
myPath = InputBox("Input the file path:")
ChDir myPath
myName = Dir("*.DOC")
While myName <> ""
With Selection
.InsertFile FileName:=myName, ConfirmConversions:=False
.InsertParagraphAfter
.InsertBreak Type:=wdSectionBreakNextPage
.Collapse Direction:=wdCollapseEnd
End With
myName = Dir()
Wend
End Sub
The problem is that the resulting document is a mess, formatting-wise. For example, let's call the created file "File A." I'm creating File A, and then inserting files B, C, and D into it. The problem is that files B, C, and D bring their headers into File A. I want File A's header to remain as it is set in the template (myTemplate.dot in the example above). Also the styles are not the same (files B, C, and D bring their styles into file A), so I'm going to need to convert styles as well.
How do I go about doing something like this? Thanks!
I am trying to consolidate all of the files in a folder into one file. Using the example from the Word VBA help file (under the "InsertFile" entry), I have it working the way that I want. Here it is:
Sub testmacro()
Dim myName As String
Dim myPath As String
Documents.Add Template:="myTemplate.DOT"
Selection.WholeStory
Selection.Collapse Direction:=wdCollapseEnd
myPath = InputBox("Input the file path:")
ChDir myPath
myName = Dir("*.DOC")
While myName <> ""
With Selection
.InsertFile FileName:=myName, ConfirmConversions:=False
.InsertParagraphAfter
.InsertBreak Type:=wdSectionBreakNextPage
.Collapse Direction:=wdCollapseEnd
End With
myName = Dir()
Wend
End Sub
The problem is that the resulting document is a mess, formatting-wise. For example, let's call the created file "File A." I'm creating File A, and then inserting files B, C, and D into it. The problem is that files B, C, and D bring their headers into File A. I want File A's header to remain as it is set in the template (myTemplate.dot in the example above). Also the styles are not the same (files B, C, and D bring their styles into file A), so I'm going to need to convert styles as well.
How do I go about doing something like this? Thanks!