Sign in to follow this  
Followers 0
fx11

Changing between Excel files

5 posts in this topic

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.

Share this post


Link to post
Share on other sites



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")

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

Send is not reliable. I suggest you using Excel UDF by water.

Search this forum and you will find it :)

Share this post


Link to post
Share on other sites

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