realtebo

After Launching Excel, the GUI doesn't close anymore

9 posts in this topic

 
Func ImportIntoExcel()
   Run ("C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE", @UserProfileDir & "\Downloads")
   WinWaitActive ("Microsoft Excel");
   Send("!AFT") ; // Dati -> Importa da testo
   WinWaitActive ("Importa fle di testo");
   Sleep(1200)
   Send("^N")
   Send("..\Downloads\")
   Send("{ENTER}")
EndFunc
 
Func CreateConfirmedPoGui()

   Local $hGUI                     = GUICreate("Ordini Amazon in stato 'confermato'",450 , 200, -1, -1, BitOR(0, $WS_SIZEBOX))
   Local $po_count                 = UBound($confirmed_po_links, $UBOUND_ROWS );
   Local $po_button[$po_count]

   For $row = 0 To ($po_count -1)
      Local $po_number = $confirmed_po_links[$row][0]
      $po_button[$row] = GUICtrlCreateButton($po_number, 5, $row*30+5)
   Next

   $import_into_excel_button = GUICtrlCreateButton("Importa CSV in Excel", 100, 5)

   GUISetState(@SW_SHOW, $hGUI)

   While 1
      Local $source = GUIGetMsg()

      If $source == $GUI_EVENT_CLOSE Then
         ExitLoop
      EndIf

      If $source == $import_into_excel_button Then
         ImportIntoExcel()
      EndIf

      For $btn = 0 to ($po_count -1)
         If ($source) == $po_button[$btn] Then
            ConsoleWrite ("Devo aprire l'ordine n. " & $confirmed_po_links[$btn][0] & @CRLF)
            OpenPo($confirmed_po_links[$btn][0])
         EndIf
      Next

   WEnd

   ; Delete the previous GUI and all controls.
   GUIDelete($hGUI)

EndFunc

 

After user click import button, I launch Ms Excel 2010 and start import procedure.

I close excel

My autoit GUI react to import button, but doesn't more react to close button (the top-right 'X', i've not  a custom close button)

What!!?!?

I must terminate the windows process to kill my gui

Share this post


Link to post
Share on other sites



Why don't you use the Excel UDF that comes with AutoIt. Much better than automating the Excel GUI.


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

I didnt' know that Excel UDF exists...  i' looking at the help files now.

Anyway, I need to import a CSV (previously downloaded from a vendor portal) into excel. I didn't see any usefull function in this situation.

Thanks anyway, but please, help me to understand what is blocking the GUI in my code.

Share this post


Link to post
Share on other sites

Solved !

I was supposing that WinWaitActive could work with open file dialog (which has a custom italian title in Excel 2010).

WinWaitActive ("Importa file di testo");

 

Removed it, all it's working well !

Share this post


Link to post
Share on other sites

But I still suggest to use the Exel UDF. It is far more reliable compared to using Send. Send always goes to the active window. So fi the user or another program steals the focus you are lost and your script hangs.

To open a CSV file is a simple 3 line task.

1 person likes this

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

I understand, but there are complex task not doable with UDF, so, instead of do some task with udf an some other with automation, and restart, I choosed to use only automation.

Actually, users are happy, so my chef is happy, so I'm happy.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

The UDF uses the COM interface. Only the most used functions are covered by the UDF. The UDF just makes using COM a bit easier.

Means:

What isn't covered by the UDF still can be coded by you by using the required methods, objects, collections and properties of the Excel object Model.

Best way to learn how to use COM is to have a look at MSDN and/or ask here ;)

Edited by water

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

This is interesting. I know really well Excel doc because I'm used to Office macros. I'll give it a study in a week or two.

But, anyway, i'm confident that in this specific case this is the better way, please, accept it.

Share this post


Link to post
Share on other sites

No problem with accepting how you solve your problems :)

Just wanted to show you a more reliable way.


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