Hi All
I am working on a macro that is able to, copy entire word files into one master word file based on selections ("x" markings) made in a excel sheet.
I got the part down with opening files and also part of the copying. My main issue is that the macro keeps overwriting the previous paste.
I am working on a macro that is able to, copy entire word files into one master word file based on selections ("x" markings) made in a excel sheet.
I got the part down with opening files and also part of the copying. My main issue is that the macro keeps overwriting the previous paste.
VBA Code:
Sub CreateAgreement()
Set objWord = CreateObject("Word.Application")
docpath = "K:\Supply Chain\Quality Support\Agreements\EN\QMF-071_01 Framework agreement template.docx"
Set wDoc = objWord.documents.Open(docpath)
objWord.Visible = True
Set wb = ActiveWorkbook
Set ws = wb.Worksheets("Selection")
lr = ws.Cells(100, "G").End(xlUp).Row
sr = 3
For i = sr To lr
If ws.Cells(i, "B") <> "" Then
docpath = ws.Cells(i, "H")
Rangeend = wDoc.Content.End - 1
wDoc.Content.InsertAfter Rangeend
Set WdCopyFrom = objWord.documents.Open(docpath)
WdCopyFrom.Activate
WdCopyFrom.Range.Copy
wDoc.Activate
wDoc.Range.Paste
'wDoc.Content.InsertParagraphAfter
End If
Next
End Sub