Friday, January 18, 2019

#1 2018-05-16 02:35:32 am

Registered: 2011-09-04
Posts: 3

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


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!

Filed under: MS-Word



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)