Results 1 to 13 of 13

Thread: Combining multiple word documents into one

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,710
    Location
    ' not sure what the heck is going on with WordApp2
    ' and wordapp - are you making two instances????
    Set WordApp2 = CreateObject("Word.Application") 
    ' OK, make a new document
    Set myDoc2 = WordApp2.Documents.Add 
    ' please note the use of the underscore character
    ' it is appreciated if you would use it!  Thanks.
    Const TARGET_FOLDER_ONEPAGE As String = _
    "P:\Clients\Vanguard\Finance\testing\onepagedocs\" 
    With wordApp      
        Set Fso = New FileSystemObject 
        Set fldr = Fso.GetFolder(TARGET_FOLDER_ONEPAGE) 
        For Each f In fldr.Files 
            If Right(f.Name, 4) = ".doc" Then 
    myDoc2.Merge Filename:= f.path
            End If 
        Next f 
    myDoc2.SaveAs _
    ("P:\Clients\Vanguard\Finance\testing\onepagedocs\allonepages.doc") 
        wordApp.Quit 
    End With 
    Set fso = Nothing
    ' etc etc etc
    This should take each f in fldr (that is a .doc) and merge it to myDoc2. However, I would definitely check to see if you need to put a page break between documents (likely). In which case, just add it to myDoc2 between the merges.
    Last edited by Aussiebear; 04-12-2023 at 06:07 PM. Reason: Adjusted the code tags

Posting Permissions

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