JasonEnsor
Programmer
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?
Regards
J.
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:
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.