captainsensible Posted March 27, 2019 Posted March 27, 2019 Suddenly started getting error "The requested action with this object has failed", if i run it manually it works just fine
Moderators JLogan3o13 Posted March 27, 2019 Moderators Posted March 27, 2019 (edited) @captainsensible how about living up to your name and actually posting your code, rather than expecting us to know what you're doing on lines 1-57... Edited March 27, 2019 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
captainsensible Posted March 27, 2019 Author Posted March 27, 2019 Local $sWorkbook8 = "M:\cotr 2019\charts 2006\chart cotr f tff 2006.xlsm" Local $oWorkbook8 = _Excel_BookOpen($oExcel, $sWorkbook8, False, True, Default, Default, 3) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook8 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oExcel.run("workbook_print") _Excel_BookClose ( $oWorkbook8, False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookClose Example 1", "Error saving workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookClose Example 1", "Workbook has been successfully closed.")
FrancescoDiMuro Posted March 27, 2019 Posted March 27, 2019 @captainsensible Where is the creation of $oExcel object? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Jfish Posted March 27, 2019 Posted March 27, 2019 (edited) And the include for Excel.au3 for the UDF function you are using ... check the excel functions in the help file. But consider starting like this: #include <Excel.au3> #include <MsgBoxConstants.au3> ; Create application object Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Edited March 27, 2019 by Jfish Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
Nine Posted March 27, 2019 Posted March 27, 2019 (edited) And that is 7 lines out of the 57 JL was talking about Edited March 27, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
water Posted March 27, 2019 Posted March 27, 2019 You are using the latest Excel UDF like the old version before it has been rewritten with AutoIt 3.3.11.4 back in 2014 (described here). There have been script breaking changes (described here). 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
captainsensible Posted March 27, 2019 Author Posted March 27, 2019 #include <Excel.au3> #include <MsgBoxConstants.au3> ; Create application object Local $oExcel = _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 $sWorkbook7 = "M:\cotr 2019\cotr price.xlsm" Local $oWorkbook7 = _Excel_BookOpen($oExcel, $sWorkbook7, True, True, Default, Default, 0) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook7 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $sWorkbook1 = "M:\cotr 2019\cotr f tff calc.xlsm" Local $oWorkbook1 = _Excel_BookOpen($oExcel, $sWorkbook1, True, True, Default, Default, 0) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook1 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $sWorkbook2 = "M:\cotr 2019\cotr fo tff calc.xlsm" Local $oWorkbook2 = _Excel_BookOpen($oExcel, $sWorkbook2, True, True, Default, Default, 0) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook2 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $sWorkbook3 = "M:\cotr 2019\cotr f disagg calc.xlsm" Local $oWorkbook3 = _Excel_BookOpen($oExcel, $sWorkbook3, True, True, Default, Default, 0) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook3 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $sWorkbook4 = "M:\cotr 2019\cotr fo disagg calc.xlsm" Local $oWorkbook4 = _Excel_BookOpen($oExcel, $sWorkbook4, True, True, Default, Default, 0) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook4 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $sWorkbook5 = "M:\cotr 2019\cotr f legacy calc.xlsm" Local $oWorkbook5 = _Excel_BookOpen($oExcel, $sWorkbook5, True, True, Default, Default, 0) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook5 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $sWorkbook6 = "M:\cotr 2019\cotr fo legacy calc.xlsm" Local $oWorkbook6 = _Excel_BookOpen($oExcel, $sWorkbook6, True, True, Default, Default, 0) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook6 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $sWorkbook8 = "M:\cotr 2019\charts 2006\chart cotr f tff 2006.xlsm" Local $oWorkbook8 = _Excel_BookOpen($oExcel, $sWorkbook8, False, True, Default, Default, 3) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook8 & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oExcel.run("workbook_print") _Excel_BookClose ( $oWorkbook8, False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookClose Example 1", "Error saving workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookClose Example 1", "Workbook has been successfully closed.")
water Posted March 27, 2019 Posted March 27, 2019 The script looks fine. But as you work with a workbook with macros it is impossible to tell what happens when you open the workbook (autorun a macro). Could you please strip down your workbook and post a reproducer (that still shows the problem) so we can have a look? 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
captainsensible Posted March 27, 2019 Author Posted March 27, 2019 (edited) Here is the actual workbook, workbook_print macro goes to default CutePDF Writer which prompts me to save the file. I wonder if the problem might be a timing problem, maybe I'm closing the workbook before the macro finishes? chart cotr f tff 2006.xlsm Edited March 27, 2019 by captainsensible Added more info
water Posted March 27, 2019 Posted March 27, 2019 The workbook opens fine and even printing to the default printer works as expected. I suggest to add a COM error handler (before the run method) for better diagnostic information: ; ... Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") $oExcel.Run("workbook_print") Func _ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc 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
captainsensible Posted March 27, 2019 Author Posted March 27, 2019 Awesome, I will definitely add the code, thank you SO MUCH for your help
SlackerAl Posted March 27, 2019 Posted March 27, 2019 I have recently had two problems with Excel failing to work from AutoIt: which was a result of a user using an add-in. The second was on office 365 where I had to force a manual update and all was then well again. Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.
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