Jump to content

Insert a word document in another open word document.


ajit
 Share

Recommended Posts

#include <Word.au3>
$sPath1 = "C:\test1.doc"
$sPath2 = "C:\test2.doc"
$oWord = _WordCreate($sPath1, 0, 1) ; visible

With $oWord.Selection
    .EndKey(6)
    .InsertBreak(7)
    .InsertFile($sPath2)
EndWith

Hi,

I have a script which inserts text from one word document to another and it works fine. I have to provide paths to both documents though.

My need is a bit different. I want to insert text from (document-2), which I can provide the path to, into another Word document (document-1) which is already opened by another program. I do not know how to achieve this.

So I have one open document and another word document (path available) from where I want to put the text to the already open document. Two documents in C drive with some text in both doc files are needed to test the script.

If there is a way to do this, please guide me.

Regards

Ajit

Link to comment
Share on other sites

A "dirty" solution would be:

#include <Word.au3>
$sPath1 = @ScriptDir&"\test1.doc"
$sPath2 = @ScriptDir&"\test2.doc"
$oWord = _WordCreate($sPath1, 0, 1) ; visible
$oDoc = _WordDocOpen($oWord,$sPath2)
Send("^a")
Sleep(200)
Send("^c")
_WordDocClose ($oDoc,0)
Sleep(200)
Send("^{END}")
Send("^{ENTER}")
Send("^v")

If you have to insert text from doc[n] to doc[n-1] you can put the files into an array.

M.I.

Link to comment
Share on other sites

@taietel

Thanks for your help. But I was just wondering if using "send method" on a continuous basis is okay, especially because there is always a risk of some other windows popping up disturbing its smooth functioning.

Will SendKeepActive ( "title" [, "text"] ) work fine and just in case it is needed where do I place it in the code during multiple sends. Is it required for every Send command or just once would suffice?

Regards

Ajit

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...