Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    May 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Combin documents into one (Word97) (Word 97 SR-2)

    Hello all,
    I've written a macro to combine word documents in a specific folder but my problem is that some of the documents are in landscape layout. I would like to combine all of the documents in original layout. Any suggestions would be greatly appreciated.

    Thanks in advance

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Combin documents into one (Word97) (Word 97 S

    The only way I can think of doing this is to open each and every file and add a section break at the end of the file before adding it to the master file. Doing this via a macro should not be too onerous but will likely be a very different method than the one you already used to insert files into the master.

    I would do it by getting the macro to open each file, add the section break and then copy the file to clipboard, close the file without saving and paste into the master. This avoids saving the new section breaks in the original files - which is a good thing.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    New Lounger
    Join Date
    May 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Combin documents into one (Word97) (Word 97 S

    Thnaks for the reply. This seems to work to a point. The first 3 files are in portrait layout and the next file is in landscape layout and the rest of the files are in portrait layout. After doing what you said, the file that's in landscape layout is in portrait and the file after that is in landscape instead of portrait. The folder consists of 23 documents and only one document is in landscape layout. My code is;

    Dim doc As Document
    Dim strFileName As String
    Dim strPath As String
    Dim strFormat As String
    Set doc = Documents.Add
    strPath = InputBox("Enter folder")
    If strPath = "" Then Exit Sub
    strFileName = Dir(strPath & "*.doc")

    Do While strFileName <> ""
    Selection.InsertFile strPath & "" & strFileName
    Selection.EndKey Unit:=wdStory
    Selection.InsertBreak Type:=wdSectionBreakNextPage
    strFileName = Dir
    Loop
    End Sub

    Again THANKS for your help and any other idea or suggestion is much appreciated.

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Combin documents into one (Word97) (Word 97 S

    The code you posted doesn't actually follow the logic suggested. If you add the section breaks after inserting the file then it is too late. If you change the code to open each file and insert the section break at the back of the file to be inserted and then copy the file into the master then you should get a better result.
    The following code illustrates the method I was suggesting.
    <pre>Sub aTest()
    Dim docMast As Document, docTemp As Document
    Dim strFileName As String
    Dim strPath As String
    Dim strFormat As String
    Set docMast = Documents.Add
    strPath = InputBox("Enter folder")
    If strPath = "" Then Exit Sub
    strFileName = Dir(strPath & "*.doc")

    Do While strFileName <> ""
    Set docTemp = Documents.Open(FileName:=strPath & "" & strFileName, _
    ReadOnly:=True, AddToRecentFiles:=False)
    docTemp.Range.Select
    Selection.EndKey Unit:=wdStory
    Selection.InsertBreak Type:=wdSectionBreakNextPage
    Selection.WholeStory
    Selection.Copy
    docTemp.Close SaveChanges:=wdDoNotSaveChanges
    docMast.Range.Select
    Selection.EndKey Unit:=wdStory
    Selection.PasteAndFormat (wdPasteDefault)
    strFileName = Dir
    Loop
    End Sub</pre>

    Improvements probably required by your final code would include conversion to use ranges rather than selection objects. Other things to consider include trying to avoid section breaks where they are not needed for example in your simple description the section breaks only need to be placed either side of the landscape doc. Which headers and footers do you want to see in the master doc? Do you want the H&F which are in the empty master or do you want to import the H&F from each of the component files?
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    New Lounger
    Join Date
    May 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Combin documents into one (Word97) (Word 97 S

    Thanks for all of the help and advice. I've learned alot from this. I had to reformat the word document and everything works GREAT. Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •