Search the Community
Showing results for tags 'Excel UDF'.
-
Hello everyone, my problem is that when I try to run my already compiled program as administrator I get this error, but when I run the script it works correctly. this is my code #include <MsgBoxConstants.au3> #include <Excel.au3> ;I use this code to not open a new excel file Global $sWorkbook = @ScriptDir & "\facturacion.xlsx" Global $oWorkbook = _Excel_BookAttach($sWorkbook) ;this line of code is the problem $num = $oWorkBook.ActiveSheet.Range("C2").value MsgBox(0,0, $num) ;this line of code is the problem $num = $oWorkBook.ActiveSheet.Range("C2").value Is there another way to obtain the data from a cell in an Excel file? Thanks for your time 😊
-
In the code below i can write the excel sheet with an array from an ADODB GetRows command But not using _Excel_RangeWrite function Thanks for your comments, #include <Array.au3> #include <Excel.au3> ;Help: COM Error Handling Global $errADODB = ObjEvent("AutoIt.Error","_ErrADODB") Local $sFilePath = @ScriptDir & "\db.mdb" Local Const $iCursorType = 0 ; adOpenForwardOnly, 3 adOpenStatic Local Const $iLockType = 3 ;1 adLockReadOnly, 3 adLockOptimistic Local Const $iOptions = 1 ; Options, 1 Evaluates as a textual definition of a command or stored procedure call ; 2 adCmdTable Global $cn = ObjCreate("ADODB.Connection") ; Create a connection object Global $rst = ObjCreate("ADODB.Recordset") ; Create a recordset object ;Global $sADOConnectionString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & $sFilePath ;Global $sADOConnectionString = 'DRIVER={Microsoft Access Driver (*.mdb)};Dbq=' & $sFilePath & ';uid=;pwd=MyPassword;' Global $sADOConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & $sFilePath & ";Jet OLEDB:Database Password=123" $cn.CursorLocation = 3 ; adUseClient ;https://stackoverflow.com/questions/31941487/open-adodb-connection-to-excel-file-in-read-only-mode ;https://www.w3schools.com/asp/prop_rec_mode.asp $cn.Mode = 1 ;Read-only ;$cn.CommandTimeout = 0 $cn.Open($sADOConnectionString) ; Open the connection Local $sSQL = "SELECT * FROM TABLE1" $rst.Open($sSQL, $cn, $iCursorType, $iLockType, $iOptions) ; Issue the SQL query If Not $rst.EOF = True Then Local $rstArray = $rst.GetRows() _ArrayDisplay ($rstArray) $rst.Close ;Create application object Local $oAppl = _Excel_Open() If @error Then Exit MsgBox(0, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; Create a new workbook with only 1 worksheet Local $oWorkbook = _Excel_BookNew($oAppl, 1) If @error Then Exit MsgBox(0, "Excel UDF: _Excel_BookNew Example 1", "Error creating new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ;MsgBox(0, "Excel UDF: _Excel_BookNew Example 1", "Workbook has been created successfully with only 1 worksheets.") Local $sSheet = $oWorkbook.ActiveSheet Local $aArray1D[3] = ["Field1", "Field2", "Field3"] $sSheet.Range("A1:C1").Font.Bold = True $sSheet.Range("A1:C1").value = $aArray1D Local $RecCount = UBound($rstArray) Local $TrstArray = $rstArray _ArrayTranspose($TrstArray) ;$sSheet.Range("A2:C" & $RecCount + 1).value = $TrstArray ;<<<<<<<<<<<<<< This writes the data OK ;This fails _Excel_RangeWrite($oWorkbook, Default, $TrstArray, "A2:C" & $RecCount + 1) If @error Then MsgBox(0, "Excel UDF: _Excel_RangeWrite Example 3", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $rst = 0 ;Release the recordset object $cn.Close ;Close the connection $cn = 0 ;Release the connection object Else $rst.Close $rst = 0 ; Release the recordset object $cn.Close ; Close the connection $cn = 0 ; Release the connection object MsgBox(262144, "", "Empty" & @CRLF & "Empty recordset" , 5) EndIf Func _ErrADODB() Msgbox(0,"ADODB COM Error","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $errADODB.description & @CRLF & _ "err.windescription:" & @TAB & $errADODB.windescription & @CRLF & _ "err.number is: " & @TAB & hex($errADODB.number,8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $errADODB.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $errADODB.scriptline & @CRLF & _ "err.source is: " & @TAB & $errADODB.source & @CRLF & _ "err.helpfile is: " & @TAB & $errADODB.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $errADODB.helpcontext, 5) Local $err = $errADODB.number If $err = 0 Then $err = -1 $rst = 0 $cmd = 0 $cn.Close $cn = 0 Exit EndFunc
-
Hi guys, See attached for an array example. to simplify what i want to achieve, I want to split this array into 9 different csv files. the first file would contain the list of "key" and the corresponding "ID1", the second would have "key" and the "ID2", the third would have "key" and "ID3" However, I want to remove all the rows that don't have an ID recorded in the respective ID2, ID3 4...5...6 etc, so the file only contains row items with a key and the ID. Would be the best way to loop through the rows and delete the row if the array field is blank - would I then need to repeat that row ID to check that the row that its replaced is also empty (ie the one after the one I just deleted)? I see this getting messy. or _arraySort, and delete everything below the last filled row? <-- this might be best? Or should I use the excel UDF, apply a filter (not selecting the blanks), then create/export to the array->csv? Super keen to hear your thoughts. thanks! IDArray.csv
- 32 replies
-
- array
- remove rows
-
(and 1 more)
Tagged with:
-
My computer has been upgraded from Office 2010 to Office 2016. Are there any features of Office 2013 or Office 2016 which you now want to see in the Excel, Word or Outlook UDF?
-
Hi guys! First of all, I want to apologize with @Melba23, @JLogan3o13, and @Jos ( I don't know why the tag sometimes works and sometimes doesn't ), for my bad attitude I have had with them. I want to explain why I was so angry, but that's not an excuse to my bad attitude... I have health problem, and lastly, I am ever more angry because I'm fighting with these problems for 5 years and I feel worse than 5 years ago, even If I had a lot of investigations about with a lot of Doctors, and there's no cure for my pathology. I don't want to touch anyone with my "story", but I wanted to explain why, sometimes, you can feel my anger in my words. I promise I'll try to be as polite as my mom taught me, and to explain all I'd like to develop, posting all you need ( sample codes... ). Now, let's talk about my project. Let's start from 0! I'd like to implement a database with AutoIt, for the warehouse management. First of all, I'd like to set some "goals" which I want to respect, developing my application: Efficiency: I'd like to develop an application that is fast as possible; Easy to make changes: I'd like to develop an application that is easy to modify, so, without too much complicated arguments; Noob-proof: As a noob as I am, my AutoIt knowledge starts from June 2016, so, I'm not a blade in this programming language. I studied C++, C, JavaScript, CSS, HTML and PHP, but, all of these programming language has a different approach comparing with AutoIt. I could be wrong in what I just estabilished! I want to tell you, again, that I'm here to listen to your suggestions, so, everything you say, it's something that I could learn, and I want to learn AutoIt, so, don't be scared to share your opinions, or your knowledge! I'm here to learn "How to AutoIt!" Ok, so, after having set some goals I'd like to hit, I want to ask you some information: What's the best way to develop a database with AutoIt? With a .txt file? With an Excel workbook? I was working on Excel workbook, but, I don't know, I could always be wrong in terms of efficiency and "easy to make changes"; I have to create a GUI, in order to let the user do things ( I think it was quite obvious ), so, I have been always used GUI functions like GUICreate and so on; anything about _GDI_Plus or something else. Most, I used _GUI* functions. What's the best way to manage different GUIs? OnEvent Mode or Message Loop "mode"? Now, I'd like to make a list of what I'd like my application would do: Reading stocks: I manage mainly 2 manufacturers, so, If I will work with an Excel workbook, I'd prefer to divide first manufacturer with the second; Add product: Simply, If a product does exist, the application prompt to the user an input box, with a sort of summary ( Product name, quantity ) of the product he's adding; ELSE, if the product does not exist, an "Add New Product" GUI should appers; Withdraw product: As a warehouse, I need to add and to withdraw product... This "function" should performs the simply task of reserach the product based on his ID and, prompt an InputBox to the user, with a little summary of the product he's withdrawing and, the quantity of the product after the withdraw; Search product: I'd like to develop a "product reserach", based on the ID of the product(s), or based on the Description of the product(s)... It'd be very nice! Create DDT: Create a DDT with a pre-formatted Excel sheet. Just insert some information, and then all the products that have been withdrawn from the database ( maximum 14 per DDT ); I have already done some of work I described here, and you can find all files you need attached to this post. I don't want you to do this. Just, don't post your code that I have been looking for, but let me try, with your help, to get an appropriate and efficient solution to what I'm asking. The last, but not the less important, the recognition I can give to you is publish your name ( or alias ) on the "developer section", more than a donation for everyone who has take part to this project. Please, if you want to know further information ( I think I've been exhaustive enough ), write here or on a PM. Another time, a big thank you to this fantastic community and, a bigger one, to the developers of this amazing and powerful programming language. Enjoy your night. Francesco PS: I will post the code tomorrow ( the most updated code ), so you can see where I have been arrived and, nothing Warehouse_Management.xlsx Gestione_Magazzino_SYS.au3
- 32 replies
-
- excel udf
- creating database
- (and 3 more)
-
Hello all, I've lurked around here for a while and learned a ton from everyone, but I can't see this issue anywhere. I've been running macros through Autoit for a while in a number of programs, but I'm having some issues with this one. Func RunMacro() Local $oExcel = _Excel_Open(False, False, False, False) ;Excel Program Local $oWorkbook = _Excel_BookOpen($oExcel, "C:/Equity Helper/Scripts/calendarmacros.xlsm", Default, Default, True) $oExcel.Run("calendarmacros.xlsm!Calendar") EndFunc When I run this bit of code everything works fine as long as the macro gets to finish. But the actual VBA calls two "Application.UserInput" fields, and if I cancel out of either the macro closes, and then AutoIt throws an error at-- $oExcel.(<---error throws here)Run("calendarmacros.xlsm!Calendar") I don't want to use autoit for the user inputs if possible, it's just easier to get the data I need for the inputs from within the VBA environment, but I'm afraid that's what's causing the problem.
-
Hi, im writing from an array to an excel sheet and want to use line breaks. The following piece of code does not do this job (instead of the line break the "[...]chr(10)[...]" is displayed in the cell: #include <Array.au3> #include <Excel.au3> #include <MsgBoxConstants.au3> ; Create application object and create a new workbook Local $oAppl = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookNew($oAppl) If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oAppl) Exit EndIf ; ***************************************************************************** ; Write a 1D array to the active sheet in the active workbook ; ***************************************************************************** Local $aArray1D[3] = ['"Zeile 1 " & vbLf & " Zeile 2"', 'B', 'CC'] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $aArray1D, "A3") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 2", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeWrite Example 2", "1D array successfully written.") What am i doing wrong? Any help is appreciated. Best regards Daniel
-
Has anyone had any luck with the "RemoveDuplicates" function of Excel in AutoIT? I have found how to do this in VBA, but I am unsure of how to convert this into AutoIT.
-
I saw in the Help File, the UDF for managing Excel 2013 and on Windows 7, but I can't manage how can I add silently a specific value in a specific cell in a specific Excel file Pls help me And yes I updated to the last version of Autoit...
-
Hi, I've some data that I need to write into an existing excel sheet.The sheet has 24 active columns (a-x) and some rows populated, 30 or so. To get my data I read a locally saved htm file and populate some vars, no problem. The question is how to then find the first blank row, write my data, move to the next row, read the next data set and write it. I've got the code done for the data loop piece, just can not for the life of me figure out the excel. I don't care if I use the excel UDF or COM calls, just need a push in the right direction please... Here is what I have so far, any help is appreciated. #include <Constants.au3> #include <Excel.au3> #include <Array.au3> #include <Date.au3> #include <File.au3> #include <String.au3> ;WinSetState("Excel","",@SW_MINIMIZE) Const $log = @ScriptDir & "\CreateDB.log" Const $sSrcPath = @ScriptDir & "\result" Const $xlPath = "\xxx\upload.xls" Local $fTgtFile Local $sCompName Local $sCompStreetAdd Local $sCompCity Local $sCompState Local $sCompZip Local $sCompCounrty Local $sCompTele Local $sNAICS Local $sNAICSDesc Local $sSIC2 Local $sSIC4 Local $sSICM Local $sSIC2Desc Local $sSIC4Desc Local $sSICMDesc Local $sMemberVar Local $sMemberTitle Local $sMemberFunc Local $sMemberPosition Local $sMemberSIC2 Local $sMemberSIC4 Local $sMemberSICM Local $sMemberRev Local $sMemberEmp _FileWriteLog($log, "***Run Start***") Local $oExcel = _ExcelBookOpen($xlPath) ;Setup Excel WinSetState("Excel","",@SW_MAXIMIZE) Sleep (1000) _ExcelSheetActivate($oExcel, "Sheet1") Local $iRows = $oExcel.ActiveSheet.UsedRange.Rows.Count Local $aHandle = _FileListToArray($sSrcPath, "*.htm",1) ; Work through the folder If @error Then MsgBox(0, "Error", "No files matched") Else ; Loop through the found files For $i = 1 To 5 ;$aHandle[0] MsgBox(4096, "File:", $aHandle[$i]) $fTgtFile = FileOpen($sSrcPath & "\" & $aHandle[$i],0) If $fTgtFile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 ;MsgBox(0, "Company City:", $sCompCity[0]) Local $line = FileReadLine($fTgtFile) If @error = -1 Then ExitLoop ;Company Name If StringInStr ($line,'companyName: "') Then $sCompName = _StringBetween($line,'companyName: "','",') EndIf ;Company Street If StringInStr ($line,'itemprop="streetAddress">') Then $sCompStreetAdd = _StringBetween($line,'itemprop="streetAddress">','</div>') EndIf ;Company City If StringInStr ($line,'city: "') Then $sCompCity = _StringBetween($line,'city: "','",') EndIf ;Company State If StringInStr ($line,'state: "') Then $sCompState = _StringBetween($line,'state: "','",') EndIf ;Company Zip If StringInStr ($line,'<span class="addresspostalCode" itemprop="postalCode">') Then $sCompZip = _StringBetween($line,'itemprop="postalCode">','</span>') EndIf ;Company Country If StringInStr ($line,'"addressCountry" class="">') Then $sCompCountry = _StringBetween($line,'class="">','<!--country-->') EndIf ;Company Telephone If StringInStr ($line,'itemprop="telephone">') Then $sCompTele = _StringBetween($line,'itemprop="telephone">','</dd>') EndIf ;NACIS If StringInStr ($line,'naics":"') Then $sNAICS = _StringBetween($line,'naics":"','"}') EndIf ;NACIS Desc If StringInStr ($line,'naics_desc":"') Then $sNAICSDesc = _StringBetween($line,'naics_desc":"','"}') EndIf ;SIC2 If StringInStr($line,'{"sic2":') Then $sSIC2 = _StringBetween($line,'{"sic2":','}') EndIf ;SIC4 If StringInStr($line,'{"sic4":') Then $sSIC4 = _StringBetween($line,'{"sic4":','}') EndIf ;SIC4 If StringInStr($line,'{"sicm":') Then $sSICM = _StringBetween($line,'{"sicm":','}') EndIf ;SIC2Desc If StringInStr($line,'{"sic2_desc":') Then $sSICM = _StringBetween($line,'{"sic2_desc":','}') EndIf ;SIC4Desc If StringInStr($line,'{"sic4_desc":') Then $sSICM = _StringBetween($line,'{"sic4_desc":','}') EndIf ;SICM_Desc If StringInStr($line,'{"sicm_desc":') Then $sSICM = _StringBetween($line,'{"sicm_desc":','}') EndIf ;Member Var If StringInStr($line,'{"member_s_var":') Then $sMemberVar= _StringBetween($line,'{"member_s_var":','}') EndIf ;Member Title If StringInStr($line,'member_attrs_title":"') Then $sMemberVar= _StringBetween($line,'member_attrs_title":"','}') EndIf ;Member Function If StringInStr($line,'{"member_function":"') Then $sMemberFunc= _StringBetween($line,'{"member_function":"','}') EndIf ;Member Position If StringInStr($line,'{"member_position":"') Then $sMemberPosition= _StringBetween($line,'{"member_position":"','}') EndIf ;Member SIC2 If StringInStr($line,'{"member_sic2":"') Then $sMemberSIC2= _StringBetween($line,'{"member_sic2":"','}') EndIf ;Member SIC4 If StringInStr($line,'{"member_sic4":') Then $sMemberSIC4= _StringBetween($line,'{"member_sic4":','}') EndIf ;Member SICM If StringInStr($line,'{"member_sicm":') Then $sMemberSICM= _StringBetween($line,'{"member_sicm":','}') EndIf ;Member Revenue If StringInStr($line,'{"member_revenue":"') Then $sMemberRev= _StringBetween($line,'{"member_revenue":','}') EndIf ;Member Employees If StringInStr($line,'{"member_employees":"') Then $sMemberRev= _StringBetween($line,'{"member_employees":','}') EndIf ;Stuck here on how to get those vars into excel :( WEnd Next EndIf Exit ; Open the workbook ;~ $oExcel = ObjCreate("Excel.Application") ;~ $oExcel = ObjCreate("Excel.Application") ;~ $oBook = $oExcel.Workbooks.Open("xxx\upload.xls") ;~ $oExcel.Visible = True ;~ $oSheet = $oBook.Worksheets(1) ;~ $oSheet.Activate ;~ $oRange = $oSheet.UsedRange ;~ $oRange.SpecialCells($xlCellTypeLastCell).Activate ;~ $newRow = $oExcel.ActiveCell.Row + 1 ;~ $oExcel.Range("A" & $newRow).Activate
-
New versions of Microsoft Office have been released since the last changes were made to the Excel UDFs. The new extensions (e.g. xlsx) are not (fully) supported and new functions are missing, performance for some functions needs to be enhanced etc. Some necessary modifications might lead to script breaking changes. To estimate the impact this will have on the community I would like you to answer the questions of this poll or add a comment to this thread. Please answer the first question of the poll even if you don't use the Excel UDF (but only the first question)!