×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

VBA Merge Multiple Word documents in to a new word document

VBA Merge Multiple Word documents in to a new word document

VBA Merge Multiple Word documents in to a new word document

(OP)
Hiya,

Wonder if someone could offer a little help. I have the code below that i am running from a userform in Word 2019. it kinda does what i want in the fact that it puts all the documents in to a final document....however it is putting them in to the document that has the userform, however i am wanting it to put them in the new document that i have created. I am probably missing something silly but i can't seem to get the selection to select the new document and then insert the files. Any ideas?

CODE --> vba

Private Sub btnCreateFinalReport_Click()
    Dim MyName
    Dim directory As String
    directory = ThisDocument.path & "\Reports\" & Me.uid & "\"
    Application.ScreenUpdating = False

    MyName = Dir(directory & "*.docx")
    
    Dim doc As Word.Application
    Set doc = New Word.Application
    
    Dim wrdDoc As Document
    doc.Documents.Add
    doc.Activate
    Set wrdDoc = doc.Documents(1)
    
    Do While MyName <> ""
        Selection.InsertFile FileName:=directory & MyName
        Selection.InsertBreak Type:=WdBreakType.wdPageBreak
        MyName = Dir
    Loop
    wrdDoc.SaveAs2 ThisDocument.path & "\Reports\" & Me.uid & "\Final.docx"
    wrdDoc.Close
Application.ScreenUpdating = True
End Sub 

Regards

J.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close