Find Save As window in Excel

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
nodochau
Pro Scripter
Posts: 135
Joined: Wed Jan 16, 2019 12:59 pm

Find Save As window in Excel

Post by nodochau » Tue Nov 03, 2020 1:56 pm

Hi All,
The goal is looking for Save As window opens then do something.
Tried to use Waitwindowopen command but it seems like not working.
Wrote codes and it does not work also. Any idea?
Thanks

Code: Select all

//find Save as window
let>start_find=0
GetWindowList>winlist
Separate>winlist,CRLF,windows
Let>x=0
while>start_find=0
  if>x=windows_count
    let>x=1
  else
    Add>x,1
  endif
  pos>Save As,windows_%x%,1,save_pos
  if>save_pos>0
    let>start_find=1
    mdl>Found Save As
EndWhile

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Find Save As window in Excel

Post by Dorian (MJT support) » Tue Nov 03, 2020 3:26 pm

I am assuming you already know about XLSave (or even XLCreate) and have deemed them unsuitable.

This will open output2.xlsx and save it as output3.xlsx

Code: Select all

XLOpen>d:\output2.xlsx,1,xlBook
XLSave>xlBook,d:\output3.xlsx
This will attach to an already open output3.xlsx and save it as output4.xlsx

Code: Select all

XLGet>d:\output3.xlsx,xlBook
XLSave>xlBook,d:\output4.xlsx
If it is a simple Save As dialog, then SetFocus>Save As should work. But as far as I am aware the more recent versions of Excel don't have the traditional Windows Save As window.

Testing with Office 365, and assuming you want to enter something into the "Enter File Name Here" box, I found that although the Find Object Wizard was able to enter the file name, it didn't seem to "register" when we clicked Save.

My workaround was to use UIGetValue to find the positions of the box, click in it, send text, and press enter. The timing below was crucial. Without the small wait, Excel became overwhelmed and the script was unreliable. You may need to increased the waits slightly.

Note that even though we're looking at "Save As", the window name is actually "output2.xlsx - Excel" - and note that some versions of Excel seem to use " - Excel" and some don't - and it's not always visible. The Find Object Wizard will figure this out for you.

Code: Select all

let>sk_delay=50
setfocus>output2.xlsx - Excel
UIGetValue>{"output2.xlsx - Excel"},{"Enter file name here"},curVals,Positions,nHeight
Separate>Positions,comma,Mouse
mousemove>Mouse_1,Mouse_2
Wait>0.1
lclick
Wait>0.1
Send>NewName
Wait>0.1
press enter
...it may also be worth trying Image Recognition.
Yes, we have a Custom Scripting Service. Message me or go here

nodochau
Pro Scripter
Posts: 135
Joined: Wed Jan 16, 2019 12:59 pm

Re: Find Save As window in Excel

Post by nodochau » Wed Nov 04, 2020 11:38 am

Thanks for your advices Dorian,
First, The excel file is not opened by MS so I don't think we can use XLSave.
Second, I don't like mousemove much :). Just use it when I don't have any choices.
After setting focus Excel I use ALT -> Send FA -> Release ALT -> set a time delay to wait the Save As window then send the path where I want to save the file to. But sometimes Excel responses slow then the program is crashed.
Images would help but it takes longer time.

Thanks

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Find Save As window in Excel

Post by Dorian (MJT support) » Wed Nov 04, 2020 1:10 pm

That's why in the second example I used XLGet to create the Book Handle before using XLSave.

XLGet was introduced in v14.4 04.
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts