rawmud Posted April 19, 2020 Posted April 19, 2020 Hi I am writing a script to get autoit to populate an excel workbook with functions. I receive an error when it comes to the _Excel_RangeWrite function. It tells me that the worksheet object is wrong or the sheet name is wrong and the com error code from Microsoft indicates that it is an incorrect function. I've tried various iterations and can't get it to work. Would you have any idea as to what I need to get it to work: Code: _Excel_RangeWrite($oWorkbook,"x", ClipGet(),$xc,TRUE) -"x" is where it fails Error: @error = 2 ; @extended = 1 @error: https://www.autoitscript.com/autoit3/docs/libfunctions/_Excel_RangeWrite.htm @extended: https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499- Examples attempted: -I have tried to set the worksheet name into a variable and load it that way #1 _Excel_RangeWrite($oWorkbook,$oWorkbook.Activatesheet, ClipGet(),$xc,TRUE) #2 Local $vWorksheet = $oWorkbook.Sheets("Data Transfer") _Excel_RangeWrite($oWorkbook,$oWorkbook.Activatesheet, ClipGet(),$xc,TRUE) #3 Local $vWorksheet ="Data Transfer" _Excel_RangeWrite($oWorkbook,$oWorkbook.Activatesheet, ClipGet(),$xc,TRUE)
Moderators Melba23 Posted April 19, 2020 Moderators Posted April 19, 2020 Moved to the appropriate forum. Moderation Team Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Nine Posted April 19, 2020 Posted April 19, 2020 There is a typo in your test it should be : _Excel_RangeWrite($oWorkbook,$oWorkbook.Activesheet, ClipGet(),$xc,TRUE) or (assuming sheet #1) _Excel_RangeWrite($oWorkbook,1, ClipGet(),$xc,TRUE) or (assuming name is right) _Excel_RangeWrite($oWorkbook,"Data Transfer", ClipGet(),$xc,TRUE) “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) Screen Scraping Multi-Threading Made Easy
rawmud Posted April 19, 2020 Author Posted April 19, 2020 So I had tried all three versions after fixing the typo and I still receive the same error. It looks like the Excel functions were changed recently and I think the worksheet reference does not work correctly? Earlier this week, it worked fine - it wasn't until Thursday that it started to go down. Below is a screenshot - typo corrected and sheet name is correct
Nine Posted April 19, 2020 Posted April 19, 2020 Upload the file, I'll check it out. “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) Screen Scraping Multi-Threading Made Easy
water Posted April 19, 2020 Posted April 19, 2020 Which version of Excel do you run? Which version of AutoIt do you run? How do you create the workbook (use _Excel_BookOpen, _Excel_BookNew, _Excel_BookAttach)? 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
rawmud Posted April 19, 2020 Author Posted April 19, 2020 Microsoft Office Home & Student 2019 AutoIT: 3.3.14.5 I am opening up an existing worksheet. I take values in a text file and copy it over to an excel spreadsheet. I had updated my windows office mid-week, that may be why it is being thrown off. excel open(), then excel book open below is the code that I am using. Thanks for the help! #include <AutoItConstants.au3> #include <WinAPI.au3> #include <Excel.au3> #include <MsgBoxConstants.au3> #include <Date.au3> #include <String.au3> ;;EXIT OPTION HotKeySet("{ESC}", "Terminate") Func Terminate() Exit EndFunc ;==>Terminate Run("NOTEPAD_FILE") Local $var = "EXCEL_FILE_LOCATION" Local $oExcel_1= _Excel_Open() Local $oWorkbook=_Excel_BookOpen($oExcel_1,$var) ClipPut("") WinSetState("NOTEPAD FILE", "", @SW_MAXIMIZE) WinActivate ("EXCEL FILE") WinSetState("EXCEL FILE","",@SW_RESTORE) WinSetState("EXCEL FILE", "", @SW_MAXIMIZE) For $i = 1 to 27 Step 1 IF $i <15 Then $h1 = 30+ 109*($i-1) ;50, 155, 210, 265,320, 375,430,485,540,595,650,705,760,815,870,925,980 ;Horizontal spacing between hourly cells: 0 109.43 218.86 328.29 437.72 547.15 656.58 766.01 875.44 984.87 1094.3 1203.73 1313.16 1422.59 $v1 = 182 $v2 = 497 $v3 = 474 $h2 = $h1+45 $h3 = $h1+55 Else $h1 = 50+ 105*($i-15) $v1 = 660 $v2 = 775 $v3 = 475 $h2 = $h1+45 $h3 = $h1+55 endif MouseClick($MOUSE_CLICK_RIGHT, $h1, $v1, 1,25) ;RIGHT cLICK MouseClick($MOUSE_CLICK_LEFT, $h2, $v2, 1,25) ; LEFT CLICK - COPY $letter = $i+64 $xc = Chr($letter)&"5" if $i = 27 Then $xc = "AA5" endif WinActivate ("EXCEL_FILE") _Excel_RangeWrite($oWorkbook,"SHEET1", ClipGet(),$xc,TRUE) ;_Excel_RangeWrite($oWorkbook,$oWorkbook.Activesheet, ClipGet(),$xc,TRUE) ;_Excel_RangeWrite($oWorkbook,3, ClipGet(),$xc,TRUE) If @error Then MsgBox(0, "Range Write Error", "@error = " & @error & ", @extended = " & @extended) ClipPut("") next
JoHanatCent Posted April 20, 2020 Posted April 20, 2020 Can you provide an example of your notepad files? I will be a lot easier to use FileReadToArray and the write to the exel file?
water Posted April 20, 2020 Posted April 20, 2020 (edited) Please check @error and @extended after each call to an _Excel_* function. Example: Local $oExcel_1= _Excel_Open() ConsoleWrite("_Excel_Open: @error=" & @error & ", @extended=" & @extended & @CRLF) Edited April 20, 2020 by water 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
rawmud Posted April 20, 2020 Author Posted April 20, 2020 I thought it'd be easier to understand with an notepad file. I can't figure why it wouldn't work, I guess it's something deeper. I am actually trying to generate a excel report from watch lists in TC2000 - a stock software. I open up the TC2000, copy symbols from a watch list and paste them into excel. Except the past function into excel stopped working. I was going to then run an excel macro to do some data manipulation. So maybe because it is an xlsm sheet, that's why? Except that it worked earlier in the week and stopped working after I updated to 2019? BELOW IS THE ACTUAL CODE. I also attached a screenshot to show you the TC2000 screen I am clicking from. I wish there was a TC2000 API, for now Autotit will work. #include <AutoItConstants.au3> #include <WinAPI.au3> #include <Excel.au3> #include <MsgBoxConstants.au3> #include <Date.au3> #include <String.au3> ;EXIT OPTION HotKeySet("{ESC}", "Terminate") Func Terminate() Exit EndFunc ;==>Terminate ;OPEN PROGRAMS (TC2000,EXCEL) Run("TC2000 EXE LOCATION") Local $var = "EXCEL FILE LOCATION" Local $oExcel_1= _Excel_Open() If @error Then MsgBox(0, "Excel Open", "@error = " & @error & ", @extended = " & @extended & @CRLF) Local $oWorkbook=_Excel_BookOpen($oExcel_1,$var) If @error Then MsgBox(0, "Excel book bopen", "@error = " & @error & ", @extended = " & @extended & @CRLF) ClipPut("") WinSetState("EXCEL FILE", "", @SW_MAXIMIZE) WinActivate ("TC2000") WinSetState("TC2000","",@SW_RESTORE) WinSetState("TC2000", "", @SW_MAXIMIZE) MouseClick($MOUSE_CLICK_LEFT, 291, 815, 1,5) ;$oWorkbook.Sheets("EXCEL SHEET").Activate For $i = 1 to 27 Step 1 WinActivate ( "TC2000") IF $i <15 Then $h1 = 30+ 109*($i-1) ;50, 155, 210, 265,320, 375,430,485,540,595,650,705,760,815,870,925,980 ;Horizontal spacing between hourly cells: 0 109.43 218.86 328.29 437.72 547.15 656.58 766.01 875.44 984.87 1094.3 1203.73 1313.16 1422.59 $v1 = 182 $v2 = 497 $v3 = 474 $h2 = $h1+45 $h3 = $h1+55 Else $h1 = 50+ 105*($i-15) $v1 = 660 $v2 = 775 $v3 = 475 $h2 = $h1+45 $h3 = $h1+55 endif MouseClick($MOUSE_CLICK_RIGHT, $h1, $v1, 1,25) ;MOVE TO TIME SYMBOL MouseClick($MOUSE_CLICK_LEFT, $h2, $v2, 1,25) ; COPY ALL SYMBOLS MouseClick($MOUSE_CLICK_LEFT, $h3, $v3, 1,25) ; COPY TO CLIPBOARD $letter = $i+64 $xc = Chr($letter)&"5" if $i = 27 Then $xc = "AA5" endif WinActivate ("EXCEL SHEET") MouseClick($MOUSE_CLICK_LEFT, 257, 786, 1,5) ;_Excel_RangeWrite($oWorkbook,"EXCEL SHEET", ClipGet(),$xc,TRUE) _Excel_RangeWrite($oWorkbook,"EXCEL SHEET", ClipGet(),$xc,TRUE) ;_Excel_RangeWrite($oWorkbook,$oWorkbook.Activesheet, ClipGet(),$xc,TRUE) ;_Excel_RangeWrite($oWorkbook,1, ClipGet(),$xc,TRUE) If @error Then MsgBox(0, "Range Write Error", "@error = " & @error & ", @extended = " & @extended) ClipPut("") next
rawmud Posted April 21, 2020 Author Posted April 21, 2020 I added in the ConsoleWrite code once I figured out what it does. Below is the output, it errors on the _Excel_Open() but still works and then throws errors on the _Excel_rangewrite. _Excel_Open: @error=0, @extended=1 _Excel_bookOpen: @error=0, @extended=0 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 _Excel_rangewrite: @error=2, @extended=1 Why is this not just simple copy/paste?
water Posted April 22, 2020 Posted April 22, 2020 Could you please replace _Excel_BookOpen with _Excel_BookNew? If it works then we know that the existing workbook causes the problem. 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
rawmud Posted April 23, 2020 Author Posted April 23, 2020 The existing workbook caused the problem. When I replaced _Excel_BookOpen with _Excel_BookNew, it fixed it. I tried to create a second version by save as and it did not work. I rebuilt the workbook and voilà, it works! Thanks everyone for your help!
water Posted April 23, 2020 Posted April 23, 2020 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