Jump to content
Sign in to follow this  
leaston

Waiting for user to choose a file?

Recommended Posts

leaston

Hi,

I'm a bit of a novice with AutoIt and am not sure the following is possible. I've searched and read through the docs, but I'm stumped as to how to proceed. Before I go ahead, would one of you kind experts please tell me if AutoIt is capable of this:

I want the end user to run a compiled script, which opens MS Excel. Once opened, I want to wait for the user to open a specific (name regularly changes) .csv file. Once opened, the script will then perform a few processes on the data in the file and display a message for the user to save the file with a new name.

So, the automated bit I'm not sure about is whether AutoIt can wait, once Excel is open, for the csv file to be loaded. I really don't expect code as the answer, but a pointer in the right direction or strong hint would be very much appreciated! :)

Thank you,

Leaston

Share this post


Link to post
Share on other sites
PsaltyDS

Hi,

I'm a bit of a novice with AutoIt and am not sure the following is possible. I've searched and read through the docs, but I'm stumped as to how to proceed. Before I go ahead, would one of you kind experts please tell me if AutoIt is capable of this:

I want the end user to run a compiled script, which opens MS Excel. Once opened, I want to wait for the user to open a specific (name regularly changes) .csv file. Once opened, the script will then perform a few processes on the data in the file and display a message for the user to save the file with a new name.

So, the automated bit I'm not sure about is whether AutoIt can wait, once Excel is open, for the csv file to be loaded. I really don't expect code as the answer, but a pointer in the right direction or strong hint would be very much appreciated! :lmao:

Thank you,

Leaston

Have you looked at the _Excel* functions of the Excel.au3 UDF in the help file?

If the script knows the file to use, it can open the file in Excel, change it, and save it without any user intervention.

Alternatively, you can use FileOpenDialog() to allow the user to specify the file and then everything else will be automated.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
leos

I think it is preferably to open the .csv file directly with the compiled script, process it with the script and save.

It is not so dificult to process .csv files in Autoit. CSV is a form of text file and means "coma separated values".

Share this post


Link to post
Share on other sites
leaston

PsaltyDS - Crikey, I didn't know those examples even existed. I'd not spotted the beta folder. Thank you, I'll have a browse through those.

leos - The problem is that I'm wanting to use some in-built Excel filters and conditional formatting as part of the process. I'm not confident enough with AutoIt to try manipulating the file contents directly yet, even at a simple level. I'm beginning to think I should have started with something a bit simpler hehe! :)

Share this post


Link to post
Share on other sites
Inverted

Manipulate all you want, just save in a different file :-D

Share this post


Link to post
Share on other sites
PsaltyDS

I'd not spotted the beta folder.

The latest version of AutoIt is 3.3.0.0 Production. The latest Beta is 3.2.13.13, older than the current "Production" version.

You should:

1. Uninstall the Beta

2. Install the latest SciTE (dated 20-12-2008)

3. Install the current AutoIt 3.3.0.0 (will also update the SciTE function tips)

Happy scripting!

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
leaston

Hello again,

I'm back with another noob question on this subject :)

I now have the latest version of AutoIt and have been playing with the tutorials and samples since posting. Things are beginning to make more sense now. I'm struggling with some of the syntax though.

My script opens Excel and I've figured out how to choose mouse clicks and send key presses to it, but there's one thing I cannot figure out. When Excel opens, I have it bringing up the File Open dialog and then it needs to pause until this window is closed. The reason is that the spreadsheet the user needs to manipulate will have a different name each time. However, even using the window tool, I don't know what syntax to use with the WinWaitClose command. The title of the file open dialog is "Open" and the Class is "bosa_sdm_XL9". What should the syntax for "WinWaitClose" be? If I'm reading the help file correctly, I think it should be:

WinWaitClose("Open") - but this doesn't work and I'm not sure what I'm doing wrong.

Thank you,

Leaston

Share this post


Link to post
Share on other sites
leaston

Doh! Never mind, I've figured it out.

I used:

WinWaitClose("[CLASS:bosa_sdm_XL9]","")

and that worked a treat.

Sorry for the wasted post above. I think writing it down helped me work through it! :)

Cheers,

Leaston

Share this post


Link to post
Share on other sites
leaston

I must be losing it. The following code doesn't work. It seems to ignore the WinWaitClose, presumably because the syntax is wrong. All I want to do is as I said in my post above. Open Excel, bring up the File Open dialog (which works), wait for the user to open their spreadsheet and continue to process the script. It isn't waiting for the File Open dialog to close.

Run("C:\Program Files\Microsoft Office\OFFICE11\excel.exe")
WinWaitActive("Microsoft Excel - Book1")
Send("!f")
Send("{DOWN}")
Send("{ENTER}")
WinWaitClose("Microsoft Excel","[CLASS:bosa_sdm_XL9]", "")
;carry on with more script....

I've also tried:

WinWaitClose("Open")

WinWaitClose("Excel", "Open")

And other variations on the theme. None of them wait for the user to manually close the dialog box.

What am I doing wrong please? Can you tell I'm a noob? :)

Thanks,

Leaston.

Share this post


Link to post
Share on other sites
PsaltyDS

I must be losing it. The following code doesn't work. It seems to ignore the WinWaitClose, presumably because the syntax is wrong. All I want to do is as I said in my post above. Open Excel, bring up the File Open dialog (which works), wait for the user to open their spreadsheet and continue to process the script. It isn't waiting for the File Open dialog to close.

Run("C:\Program Files\Microsoft Office\OFFICE11\excel.exe")
WinWaitActive("Microsoft Excel - Book1")
Send("!f")
Send("{DOWN}")
Send("{ENTER}")
WinWaitClose("Microsoft Excel","[CLASS:bosa_sdm_XL9]", "")
;carry on with more script....

I've also tried:

WinWaitClose("Open")

WinWaitClose("Excel", "Open")

And other variations on the theme. None of them wait for the user to manually close the dialog box.

What am I doing wrong please? Can you tell I'm a noob? :)

Thanks,

Leaston.

You moved "[CLASS:bosa_sdm_XL9]" from the window title parameter, where it belonged, to the text parameter. If you want to combine the title string with the class, it would look like this:
WinWaitClose("[CLASS:bosa_sdm_XL9; TITLE:Microsoft Excel]", "")

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
leaston

That still didn't work. According to Window Info, the MS Excel File Open dialog is as follows:

Title: Open

Class:bosa_sdm_XL9

So, even changing the line to:

WinWaitClose("[CLASS:bosa_sdm_XL9; TITLE:Open]", "")

doesn't halt the execution of the script at this point. It just carries on processing and actually closes the dialog for me. :)

Also tried:

WinWaitClose("[CLASS:bosa_sdm_XL9; TITLE:Microsoft Excel]", "")

WinWaitClose("[CLASS:bosa_sdm_XL9; TITLE:Excel]", "")

To no avail.

Sorry, I meant to say. I'm not bothered about combining title string and class. The only reason I used it this way is because I saw an example with something similar after failing to get it working in other ways. As long as my script halts when the File Open dialog is being displayed and carries on when it closes, I don't care. :)

Edited by leaston

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.