tkeaston14 Posted October 8, 2015 Posted October 8, 2015 Hello, I wrote a script that opens an excel file on my desktop, runs a module macro, saves the file as csv, and exits, however when I get to the post Save As screen where I must confirm that some features will not carry over to CSV I cannot get the script to send the Enter command for some reason. Here is my code. expandcollapse popup#region --- Au3Recorder generated code Start (v3.3.9.5 KeyboardLayout=00000409) --- #region --- Internal functions Au3Recorder Start --- Func _Au3RecordSetup() Opt('WinWaitDelay',100) Opt('WinDetectHiddenText',1) Opt('MouseCoordMode',0) Local $aResult = DllCall('User32.dll', 'int', 'GetKeyboardLayoutNameW', 'wstr', '') If $aResult[1] <> '00000409' Then MsgBox(64, 'Warning', 'Recording has been done under a different Keyboard layout' & @CRLF & '(00000409->' & $aResult[1] & ')') EndIf EndFunc Func _WinWaitActivate($title,$text,$timeout=0) WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) EndFunc _AU3RecordSetup() #endregion --- Internal functions Au3Recorder End --- Send("a{ENTER}") _WinWaitActivate("Microsoft Excel - Abacus List","") Send("{ALTDOWN}{F11}{ALTUP}") Send("{ALTDOWN}{I}{ALTUP}") Send("{M}") _WinWaitActivate("Microsoft Visual Basic for Applications - Abacus List.xlsx","") Send("Sub sbVBS_To_delete_firstFewRows_in_Excel() {ENTER} Rows(1).EntireRow.Delete {ENTER} Rows(1).EntireRow.Delete {ENTER} Rows(1).EntireRow.Delete {ENTER} Rows(1).EntireRow.Delete {ENTER} Rows(1).EntireRow.Delete {ENTER} Columns([1]).EntireColumn.Delete {ENTER} Columns([1]).EntireColumn.Delete") Send ("{F5}") Send ("{ALTDOWN}{F4}{ALTUP}") _WinWaitActivate("Microsoft Excel - Abacus List","") Sleep(2000) Send("{F12}") Sleep(2000) _WinWaitActivate("Save As","") Sleep(2000) Send("{TAB}c{ENTER}") Sleep(2000) _WinWaitActivate("Confirm Save As","") Send("{ENTER}") _WinWaitActivate("Microsoft Excel","") Send("{ENTER}") #endregion --- Au3Recorder generated code End ---
JohnOne Posted October 8, 2015 Posted October 8, 2015 I have no time to look at such a script, but have you considered The _Excel_* functions from standard excel UDF? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
tkeaston14 Posted October 9, 2015 Author Posted October 9, 2015 Ok updated the code to use the Excel UDF with some standard inputs. However, my initial issue still stands where it will not send Enter to the last save dialog box. Any ideas? Updated Codeexpandcollapse popup#include <Excel.au3> #include <MsgBoxConstants.au3> ; Create application object Local $oAppl = _Excel_Open() If @error Then Exit MsgBox(16, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; ***************************************************************************** ; Open an existing workbook and return its object identifier. ; ***************************************************************************** Local $sWorkbook = @ScriptDir & "\Abacus List.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook, Default, Default, True) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Sleep(2000) Sleep(2000) Sleep(2000) Send("{ENTER}") Send("{ALTDOWN}{F11}{ALTUP}") Send("{ALTDOWN}{I}{ALTUP}") Send("{M}") Sleep(2000) Send("Sub sbVBS_To_delete_firstFewRows_in_Excel() {ENTER} Rows(1).EntireRow.Delete {ENTER} Rows(1).EntireRow.Delete {ENTER} Rows(1).EntireRow.Delete {ENTER} Rows(1).EntireRow.Delete {ENTER} Rows(1).EntireRow.Delete {ENTER} Columns([1]).EntireColumn.Delete {ENTER} Columns([1]).EntireColumn.Delete") Send ("{F5}") Sleep(2000) Sleep(2000) Sleep(2000) Sleep(2000) Send ("{ALTDOWN}{F4}{ALTUP}") Sleep(2000) Sleep(2000) Sleep(2000) Send("{F12}") Sleep(2000) Sleep(2000) Sleep(2000) Sleep(2000) Send("{TAB}c{ENTER}") Sleep(2000) Sleep(2000) Send("{TAB}{ENTER}") Sleep(2000) Sleep(2000) Send("{ENTER}") Sleep(2000) Sleep(2000) Sleep(2000) _Excel_BookClose($oWorkbook, False) Send("{TAB}{ENTER}") Sleep(2000) Sleep(2000) Send ("{ALTDOWN}{F4}{ALTUP}")
water Posted October 9, 2015 Posted October 9, 2015 Saving a worbook can as well be done using a function from the Excel UDF: _Excel_BookSave or _Excel_BookSaveAs. 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