Jadog Posted September 6, 2021 Share Posted September 6, 2021 For some reason I'm having trouble with the below script. A year ago it was running fine. $oExcel = _Excel_BookOpen("C:\Users\think\Desktop\ExcelFileHere.xls", 1) If @error = 1 Then MsgBox(0, "Error!", "Unable to Create the Excel Object") Exit ElseIf @error = 2 Then MsgBox(0, "Error!", "File does not exist!") Exit EndIf Link to comment Share on other sites More sharing options...
Musashi Posted September 7, 2021 Share Posted September 7, 2021 2 hours ago, Jadog said: For some reason I'm having trouble with the below script. A year ago it was running fine. $oExcel = _Excel_BookOpen("C:\Users\think\Desktop\ExcelFileHere.xls", 1) If @error = 1 Then MsgBox(0, "Error!", "Unable to Create the Excel Object") Exit ElseIf @error = 2 Then MsgBox(0, "Error!", "File does not exist!") Exit EndIf I don't use Excel, but according to the help, shouldn't it look like this ? : #include <Excel.au3> #include <MsgBoxConstants.au3> Local $oExcel, $oWorkbook $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "_Excel_Open Error", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\Extras\_Excel1.xls") Switch @error Case 1 Exit MsgBox($MB_SYSTEMMODAL, "_Excel_BookOpen Error 1", "$oExcel is not an object or not an application object") Case 2 Exit MsgBox($MB_SYSTEMMODAL, "_Excel_BookOpen Error 2", "Specified $sFilePath does not exist") Case 3 Exit MsgBox($MB_SYSTEMMODAL, "_Excel_BookOpen Error 3", "Unable to open $sFilePath. @extended is set to the COM error code returned by the Open method") EndSwitch ; [...] "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Jadog Posted September 7, 2021 Author Share Posted September 7, 2021 My help doesn't show that one. Is there an online help somewhere that shows this? Link to comment Share on other sites More sharing options...
water Posted September 7, 2021 Share Posted September 7, 2021 Which version of AutoIt do you run? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Musashi Posted September 7, 2021 Share Posted September 7, 2021 3 hours ago, Jadog said: My help doesn't show that one. Is there an online help somewhere that shows this? My script is a little variation of the example from the help on _Excel_BookOpen . Quote Parameters $oExcel Excel application object where you want to open the workbook $sFilePath Path and filename of the file to be opened According to this, the first parameter must be an Excel application object, not a path. Your code snippet is also missing the preceding call of _Excel_Open . It was apparently different in older versions, hence the question from @water. Take a look at : https://www.autoitscript.com/wiki/Excel_UDF Quote It's mandatory now to call function _Excel_Open before any other function (except _Excel_BookAttach). This function didn't exist in the old UDF. @extended is set if Excel was already running. "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
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