#include #include Global $oExcel = _Excel_Open(False) Global $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\dataload2.xlsx") Global $aDocuments = _Excel_RangeRead($oWorkbook) _Excel_Close($oExcel, False) Global $oWord = _Word_Create() Global $oDocMaster, $oDoc, $i, $j For $i = 0 To UBound($aDocuments, 1) - 1 $oDocMaster = _Word_DocAdd($oWord) ; Start a new document for every row Global $oRange = _Word_DocRangeSet($oDocMaster, -1) For $j = 0 To UBound($aDocuments, 2) - 2 ; last element of the row holds the path of $oDocMaster If $aDocuments[$i][$j] <> "" Then $oRange.InsertFile($aDocuments[$i][$j]) $oRange = _Word_DocRangeSet($oDocMaster, -2) $oRange.InsertBreak($WdPageBreak) EndIf Next ConsoleWrite($aDocuments[$i][UBound($aDocuments, 2) - 1] & @CRLF) _Word_DocSaveAs($oDocMaster, $aDocuments[$i][UBound($aDocuments, 2) - 1], $WdFormatDocumentDefault) ; Save master document ConsoleWrite(@error & @CRLF) _Word_DocClose($oDocMaster) ; Close document Next _Word_Quit($oWord)