Using VB in Access to Copy & Paste from 1 Word doc to another (1 Viewer)

AlanJBS

New member
Local time
Yesterday, 17:39
Joined
Feb 12, 2009
Messages
10
I regularly write code to create a Word document from Access, and then populate it with some data from the database.

Now what I would like to do it also open a second Word document (which already exists) and copy and paste the content from document 2 into the newly created first document.

I have got as far as opening the 2nd document and copying its contents (I have checked the clipboard contents to see it’s there), but I have not yet worked out how to paste it into the first document. Here is my code so far:

Set myWDApp = CreateObject("Word.Application")

myWDApp.Documents.Add Template:="" & TemplateChoice & ""

Set myRange = myWDApp.ActiveDocument.Range(myWDApp.ActiveDocument.Paragraphs(1).Range.Start, myWDApp.ActiveDocument.Paragraphs(6).Range.End)

With myRange
.insert varSomeDataFromTheDatabase


myWDApp.Documents.Open fileName:="AnotherExisting.doc" [Open 2nd document]

myWDApp.ActiveDocument.Content.Copy [Copies 2nd document contents]

...and from here I cannot get the copied stuff pasted into document 1!!

Any help appreciated!

Regards
Alan
 

Users who are viewing this thread

Top Bottom