Sign in to follow this  
Followers 0
Zieq

Copying a word document to another document

7 posts in this topic

#1 ·  Posted (edited)

Hello,

I am implementing a repetitive process of my project through autoit and  I have a workflow in which i am having two word file.
 

1.In the first file i have a table and  i want to type text in 1st row,  2nd column and i want to copy(Screenshot taken by PrtSc) from clipboard to end of page,  and now  i want to copy all content to clipboard and close this file without saving.

2. And in second doc file i want to copy all data from clipboard to end of file and save it before closing.

i want to do these 1,2 operation repeatedly with HotKeySet()..

Below is the code i am writing, its executing for the first time but not executing second time. Please help me. thanks in advance.

Func Copy()
 
$oword = ObjCreate("Word.Application")
$oword.visible = True
$oword.Documents.open("Evidence_Copy.docx")
$oword.Selection.Move($wdCell,1) ;moving to another cell
$oword.Selection.TypeText("1")
$oword.Selection.Move($wdSection,1)  ;moving to end of page
$oword.Selection.Paste()                      ;pasting from clipboard
$oword.Selection.WholeStory               ;selecting whole document
$oword.Selection.Copy()                      ; copy all content
 
 
$word = ObjCreate("Word.Application")
$word.visible = True
$word.Documents.open("Evidence.doc")
$word.Selection.Move($wdSection,1)               ;end of page
$word.Selection.Paste()
 
$oword.Documents.Close($WdDoNotSaveChanges)
$oword.Application.Quit()
$word.Documents.Close($wdSaveChanges)
$word.Application.Quit()
EndFunc
Edited by Zieq

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi Zieq,

 and welcome to the forums !

This is only the function, the execute part is missing, which is where you said the problem was...

Bill

Please post the entire script and please use the Post Your Code instructions located in my sig  ;)

Edited by l3ill

Share this post


Link to post
Share on other sites

#include <Word.au3>
#include <WordConstants.au3>
HotKeySet("+^j", "Copy") 
Func Copy()


$oword = ObjCreate("Word.Application")
$oword.visible = False
$oword.Documents.open("Evidence_Copy.docx")
$oword.Selection.Move($wdCell,1)
$oword.Selection.TypeText("1")
$oword.Selection.Move($wdSection,1)
$oword.Selection.Paste()
$oword.Selection.WholeStory


$oword.Selection.Copy()




$word = ObjCreate("Word.Application")
$word.visible = True
$word.Documents.open("Evidence.docx")
$word.Selection.Move($wdSection,1)
$word.Selection.Paste()
$word.Application.Save()


$oword.Documents.Close($WdDoNotSaveChanges)
$oword.Application.Quit()
$word.Documents.Close($wdSaveChanges)
$word.Application.Quit()
EndFunc

Evidence_Copy.docx

Evidence.docx

Share this post


Link to post
Share on other sites

Okay, the 2 problems Ive found so far is that you need a while loop to keep the key set active.

And you choice of Shortcut was colliding with the one in Scite.

Try this and see if you get any further

HotKeySet("+^5", "Copy")

While 1
        Sleep(1000)
WEnd

Good Luck !

Bill

Share this post


Link to post
Share on other sites

AutoIt comes with a Word UDF that should help you to do what you want.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks MVPs and dabbler

I have another piece of code which executes with HotKeySet("^!j")
 

$word = ObjCreate("Word.Application")
$word.visible = True
$word.Documents.open(@ScriptDir &"\"&"Evidence_Copy.docx")
$word.Selection.Find.Execute("Step No.:")
$word.Selection.Move(1,2)
$word.Selection.TypeText($nCurrentStep)
$word.Selection.Move($wdSection,1)
$word.Selection.TypeText(@CRLF)
$word.Selection.TypeText(@CRLF)
 $word.Selection.Paste()
$word.Documents.Close($WdDoNotSaveChanges )
$word.Application.Quit()

i have problem in $word.Selection.TypeText($nCurrentStep) my app gets closed when this line executes for 2nd time

$ nCurrentStep is global, when i use this to show value in msgbox it shows correct value.

Any help would be appreciated :)
Thanks in advance.

 

Evidence_Copy.docx

Share this post


Link to post
Share on other sites

I suggest to add a COM error handler to your script. This will give you more detailed error information.

Check function ObjEvent in the help file for an example.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0