SkysLastChance Posted November 2, 2016 Posted November 2, 2016 #Include <Excel.au3> #Include <File.au3> Dim $oExcel, $sExcelFile, $ms Dim $fExcelVisible = 1 ;Change this to 0 for Production While ProcessExists("EXCEL.EXE") $ms = MsgBox(5,"","Process error. You have an Excel sheet open. You must close it in order to let this program work. Please close it now.") ;Retry=4 and Cancel=2 If $ms=2 Then Exit Sleep(250) WEnd $sExcelFile = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xls)") ;Changed $oExcel to $sExcelFile If FileExists($sExcelFile) Then MsgBox(0,"","open selected book__") $oExcel = _ExcelBookOpen($sExcelFile,$fExcelVisible, False);this will open the chosen xls file. If IsObj($oExcel) Then ConsoleWrite("Excel book " & $sExcelFile & " has been opened." & @CRLF) Else $oExcel = _ExcelBookNew($fExcelVisible);this is here to create the xls file if it does not exist. _ExcelBookSaveAs($oExcel,$sExcelFile) ;Save it immediately _ExcelWriteCell($oExcel,"Testing2",1,4);title line EndIf _ExcelBookClose($oExcel, 1) ;Save and close ProcessClose("EXCEL.EXE") MsgBox(0,"Done","Done",10) Not sure why this is coming up as a error. Any help would be appriecated. $oExcel = _ExcelBookOpen($sExcelFile,$fExcelVisible, False) $oExcel = ^ ERROR You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott
water Posted November 2, 2016 Posted November 2, 2016 Which version of AutoIt do you run? What's the exact error text you see in the SciTE output pane? 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
SkysLastChance Posted November 2, 2016 Author Posted November 2, 2016 I have the most current I believe, however I used the zip file. just got it a couple days ago. >"C:\Users\vmitchell\Desktop\AutoIt\SciTe\..\autoit3.exe" /ErrorStdOut "J:\MCK Clinic Ops Training\Portal\Vaughn\Test\AutoIt Scripts\Test3.au3" "J:\MCK Clinic Ops Training\Portal\Vaughn\Test\AutoIt Scripts\Test3.au3" (13) : ==> Unknown function name.: $oExcel = _ExcelBookOpen($sExcelFile,$fExcelVisible, False) $oExcel = ^ ERROR >Exit code: 1 Time: 4.956 You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott
water Posted November 2, 2016 Posted November 2, 2016 I see. The Excel UDF has been completely rewritten with version 3.3.12.0 of AutoIt. The function names etc. have been changed. Details can be found here: https://www.autoitscript.com/autoit3/docs/script_breaking_changes_excel_udf.htm SkysLastChance 1 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
SkysLastChance Posted November 2, 2016 Author Posted November 2, 2016 Oh wow, Thank you. You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott
SkysLastChance Posted November 2, 2016 Author Posted November 2, 2016 #Include <Excel.au3> #Include <File.au3> Dim $oExcel, $sExcelFile, $ms Dim $fExcelVisible = 1 ;Change this to 0 for Production While ProcessExists("EXCEL.EXE") $ms = MsgBox(5,"","Process error. You have an Excel sheet open. You must close it in order to let this program work. Please close it now.") If $ms=2 Then Exit Sleep(250) WEnd $sExcelFile = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xls)") If FileExists($sExcelFile) Then MsgBox(0,"","open selected book__") $oExcel = _Excel_Open($sExcelFile);this will open the chosen xls file. If IsObj($oExcel) Then ConsoleWrite("Excel book " & $sExcelFile & " has been opened." & @CRLF) Else $oExcel = _Excel_Open() $oWorkbook = _Excel_BookNew($oExcel, 2);this is here to create the xls file if it does not exist. EndIf Okay, I made the changes and the "Else" code is working great again, however the if will act like it is loading and then the excel will not load. I get no error so I am not sure what part of the code is not working. Might be easier to just go back to the old code >.< You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott
SkysLastChance Posted November 2, 2016 Author Posted November 2, 2016 #Include <Excel.au3> #Include <File.au3> Dim $oExcel, $sExcelFile, $ms While ProcessExists("EXCEL.EXE") $ms = MsgBox(5,"","Process error. You have an Excel sheet open. You must close it in order to let this program work. Please close it now.") If $ms=2 Then Exit Sleep(250) WEnd $sExcelFile = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xls)") If FileExists($sExcelFile) Then MsgBox(0,"","Book Opened") $oExcel = _Excel_Open () $oExcel = _Excel_BookOpen($oExcel,$sExcelFile) ;this will open the chosen xls file. If IsObj($oExcel) Then ConsoleWrite("Excel book " & $sExcelFile & " has been opened." & @CRLF) Else $oExcel = _Excel_Open() $oWorkbook = _Excel_BookNew($oExcel, 2);this is here to create the xls file if it does not exist. EndIf Okay, confirmed still a big noob. I got it working and I don't want to talk about it. Here it is just in case this helps anyone else. I don't know what I would do without you water. You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott
water Posted November 3, 2016 Posted November 3, 2016 I would add some minor modifications to make it more readable: #Include <Excel.au3> #Include <File.au3> Global $oExcel, $sExcelFile, $ms While ProcessExists("EXCEL.EXE") $iReply = MsgBox(5,"","Process error. You have an Excel sheet open. You must close it in order to let this program work. Please close it now.") If $iReply = 2 Then Exit Sleep(250) WEnd $sExcelFile = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xls)") $oExcel = _Excel_Open() If FileExists($sExcelFile) Then MsgBox(0,"","Book Opened") $oWorkbook = _Excel_BookOpen($oExcel,$sExcelFile) ;this will open the chosen xls file. If @error = 0 Then ConsoleWrite("Excel book " & $sExcelFile & " has been opened." & @CRLF) Else $oWorkbook = _Excel_BookNew($oExcel, 2);this is here to create the xls file if it does not exist. EndIf SkysLastChance and 232showtime 2 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
SkysLastChance Posted November 3, 2016 Author Posted November 3, 2016 So Clean. I really appreciate you taking the time to clean that up for me. Thank you so much. You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott
water Posted November 3, 2016 Posted November 3, 2016 Another idea is not to check for a running Excel instance but for open workbooks. If you like I can post an example. SkysLastChance 1 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
SkysLastChance Posted November 3, 2016 Author Posted November 3, 2016 Yeah that would be great. I am always trying to improve my code. You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott
water Posted November 3, 2016 Posted November 3, 2016 After _Excel_Open you could call _Excel_Booklist. If you get an empty array no workbooks are open. SkysLastChance 1 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