How to insert a file at the end of a Word document?

Hello,

I’m trying to insert a Word document into another Word Document, but when I do, the file is inserted at the beginning, despite my attempt at inserting it at the end of the document (assuming, of course, that the receiving document has text already in it). I assume that setting the range the way I do is the problem, but it works well when I insert plain text. It does not work when inserting files.

Here’s the code:

on AddAttachmentFileToWordDoc(FilePath)
	tell application "Microsoft Word"
		set ContTemp to content of text object
		set StartRange to (count of ContTemp) - 1
		set endrange to StartRange
		set theRange to create range start StartRange end endrange
		tell theRange
			insert file at end file name (FilePath as text)
		end tell
	end tell
end AddAttachmentFileToWordDoc

Where FilePath is the path to the document to be inserted.

Any ideas? Thanks!


set theFirstDocx to (choose file with prompt "Select Destination DocX document") as text
delay 1
set theSecondDocx to (choose file with prompt "Select DocX to append to Destination DocX document") as text

tell application "Microsoft Word"
	activate
	make new document
	
	insert file at text object of selection file name theSecondDocx
	insert break at text object of selection break type page break
	insert file at text object of selection file name theFirstDocx
	
	save as active document file name theFirstDocx
end tell

OR:


on AddAttachmentFileToWordDoc(FilePath) -- FilePath will be as "Untitled:Users:123:Documents:Welcome.docx"
	
	tell application "Microsoft Word"
		activate
		set theFirstDocx to full name of active document
		tell active document to close
	end tell
	
	delay 5
	
	tell application "Microsoft Word"
		activate
		make new document
		insert file at text object of selection file name FilePath
		insert break at text object of selection break type page break
		insert file at text object of selection file name theFirstDocx
		save as active document file name theFirstDocx
	end tell
	
end AddAttachmentFileToWordDoc