fx11 Posted January 9, 2014 Posted January 9, 2014 Hi, members! I have just started learning about making AutoIt scripts. I would like to copy datas from one Excel file to another. I use Excel 2003. I have two files named: MyExFile1.xls and MyExFile2.xls First I open all the two files manually. MyExFile1.xls is the active window. When I use WinActivate("MyExFile2.xls") function in a script, it does not make switch from MyExFile1.xls to MyExFile2.xls. MyExFile1.xls stays the active window and MyExFile2.xls DOES NOT become active. How can I solve this? Thanks.
Solution michaelslamet Posted January 9, 2014 Solution Posted January 9, 2014 Hi fx11, Welcome to the forum! Because "MyExFile2.xls" is not the exact title of the window. It might be something like: Microsoft Excel 2003 - MyExFile2.xls And read about Opt("WinTitleMatchMode")
fx11 Posted January 9, 2014 Author Posted January 9, 2014 Hi michaelslamet! Thanks for your help. Now it works as I wish. And it does it relatively fast. Here is what I've tried: contents of MyExFile1.xls in column A:1 2 3 4 contents of MyExFile2.xls in column A:828210 828211 828212 828213 828214 828215 828216 828217 828218 828219 828220 --------------------------------------------------------------------------------My Script: AutoItSetOption("WinTitleMatchMode", 2) ;2 = Match any substring in the title WinActivate("MyExFile1.xls") WinWaitActive("MyExFile1.xls") Send("btype") Send("{ENTER}") WinActivate("MyExFile2.xls") WinWaitActive("MyExFile2.xls") Send("ordnum") Send("{ENTER}") --------------------------------------------------------------------------------Results after running it: contents of MyExFile1.xls in column A:btype 2 3 4 contents of MyExFile2.xls in column A:ordnum 828211 828212 828213 828214 828215 828216 828217 828218 828219 828220
michaelslamet Posted January 9, 2014 Posted January 9, 2014 Send is not reliable. I suggest you using Excel UDF by water. Search this forum and you will find it
water Posted January 9, 2014 Posted January 9, 2014 In my signature you'll find the link to the rewrite of the Excel UDF (this will become part of the next AutoIt version). Function _Excel_RangeCopyPaste should allow to copy a range of cells from one workbook to another. See example 2 in the example script. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now