Jump to content

Copying a word document to another document


Zieq
 Share

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
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

Link to comment
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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...