Mkhan Posted January 12, 2022 Posted January 12, 2022 I am running a series of tasks in excel with the help of Autoit. I've relied on the material online to get so far and have been running my scripts for sometime now. The script works fine, for weeks without issues, but sometimes I get this error. Usually if I reboot the system and re-run the scripts the issues resolves itself but I cant seem to get past it this time. I am using $oExcelWorkbook.ActiveSheet.Name to get the name of my active sheet. I want to check the name of the active sheet and change it to the sheet I want it to be , if it is not that sheet. Below is a snippet of the code. ;Open file Global $oExcel = _Excel_Open() Global $sFilePathDailyOP = "C:\Users\...." $oDailyOP = _Excel_BookOpen($oExcel, $sFilePathDailyOP) Sleep(10000) ;Adjust sheet selection Local $sCurrentsheet = $oDailyOP.ActiveSheet.Name ; THIS IS THE LINE I Get the Error At Local $sSheetneeded = "PI 5 sec Data" If $sCurrentsheet <> $sSheetneeded Then $oDailyOP.Sheets("PI 5 sec Data").Select EndIf $oDailyOP.ActiveSheet.Range("A8:BB17288").Select Sleep(1000) Here's a snippet of the error I would appreciate any help with the error. Thank you
Danp2 Posted January 12, 2022 Posted January 12, 2022 _Excel_BookOpen is likely failing to open the workbook. You should check the value of @error immediately after calling this function to see why it is failing. Mkhan 1 Latest Webdriver UDF Release Webdriver Wiki FAQs
Mkhan Posted January 12, 2022 Author Posted January 12, 2022 6 minutes ago, Danp2 said: _Excel_BookOpen is likely failing to open the workbook. You should check the value of @error immediately after calling this function to see why it is failing. I added this after _ExcelOpen() : MsgBox(0, "", "Open: " & @error) and this after _EXCEL_BookOpen() : MsgBox(0, "", "BookOpen: " & @error) Got these Messages How do I check what this means.
Mkhan Posted January 12, 2022 Author Posted January 12, 2022 28 minutes ago, Mkhan said: I added this after _ExcelOpen() : MsgBox(0, "", "Open: " & @error) and this after _EXCEL_BookOpen() : MsgBox(0, "", "BookOpen: " & @error) Got these Messages How do I check what this means. My script has a loop in which I am creating the excel file by copying from a previous version and naming it differently. I am using FileCopy () for that. The script seems to have trouble creating a copy of the excel file in some instances and as a result BookOpen fails because the file was not created. S Before I close the excel is saved, but in some instances autoit is having trouble saving the file as well, resulting in not have a file to copy when the loop restarts. I use _Excel_Close($oWorkbook) to close the excel.
Nine Posted January 12, 2022 Posted January 12, 2022 You may want to try setting $bSaveChanges and $bForceClose to True like this : Excel_Close($oWorkbook, True, True) Mkhan 1 “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
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