jahjah Posted March 1, 2011 Share Posted March 1, 2011 (edited) Hello everybody,Can somebody could help me to user the fonction autofilter in excel with autoit??Here his my trouble:I open a excel file then i try to apply to this Worksheet a filter with auto itplease somebody give me some adviceHere is a part of my script$oExcel.ActiveWorkbook.Sheets("Feuil1").Select()Local $nb_colonne = $oExcel.ActiveSheet.UsedRange.Columns.Count ; Compte le nombre de colonnes actives de "ONGLET_SOURCE"Local $nb_ligne = $oExcel.ActiveSheet.UsedRange.Rows.Count ; Compte le nombre de lignes actives de "ONGLET_SOURCE"MsgBox (0,"debug",$nb_colonne)MsgBox (0,"debug",$nb_ligne)Local $xlFilterInPlace = 1 ; Constante VBA = Leave data in place for AdvancedFilter$oExcel.Sheets("Feuil1").Range( _ $oExcel.Cells("A5,O2596"), $oExcel.Cells($nb_ligne+1,$nb_colonne+1) _).AdvancedFilter( _ $xlFilterInPlace, $oExcel.Sheets("FILTRE_ELABORE").Range("A1:A2"), false ) Edited March 1, 2011 by jahjah Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 1, 2011 Share Posted March 1, 2011 Search for Excel_udf.au3 ; #FUNCTION# ==================================================================================================================== ; Name...........: _ExcelFilter ; Description ...: Applies a filter to an excel file. ; Syntax.........: _ExcelFilter($oExcel,$sRangeorRow, $iColumn, $sField, $sCriteria) ; Parameters ....: $oExcel - An Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew() ; $sRangeOrRow - The range in A1 format, or a row number for R1C1 format ; $iColumn - The specified column number for R1C1 format (default = 1) ; $sField- the field no. where filter is to be applied. ; $sCriteria- the criteria for filter is to be applied. For e.g filter by country name "India". ; Return values .: Success - Returns 1 ; Failure - Returns 0 and sets @error on errors: ; @error=1 - Specified object does not exist ; @error=2 - Row or column invalid ; @extended=0 - Row invalid ; @extended=1 - Column invalid ; Author ........: Manjish Naik (naikma@gmail.com) ; Modified.......: None as yet ; Remarks .......: None ; Related .......: ; Link ..........; ; Example .......; _ExcelFilter($oExcel,1,2,2,"Amit Ravindra,Patil"), this filters out all entries except the one having "Manager Name" as "Amit Ravindra,Patil". ; The "manager name" is second filter field located at 1 row and 2nd column, hence $sField=2. ; =============================================================================================================================== Func _ExcelFilter($oExcel, $sRangeOrRow, $iColumn, $sField, $sCriteria) If Not StringRegExp($sRangeOrRow, "[A-Z,a-z]", 0) Then If $sRangeOrRow < 1 Then Return SetError(2, 0, 0) If $iColumn < 1 Then Return SetError(2, 1, 0) $oExcel.ActiveSheet.Cells($sRangeOrRow, $iColumn).Select $oExcel.selection.Autofilter($sField, $sCriteria) Else $oExcel.ActiveSheet.Range($sRangeOrRow).Select $oExcel.selection.Autofilter($sField, $sCriteria) EndIf EndFunc ;==>_ExcelFilter Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
water Posted March 1, 2011 Share Posted March 1, 2011 Can somebody could help me to user the fonction autofilter in excel with autoit?? ... ).AdvancedFilter( _ $xlFilterInPlace, $oExcel.Sheets("FILTRE_ELABORE").Range("A1:A2"), false ) Are you trying to use Autofilter or Advancedfilter? If you try to use Advancedfilter then the number of parameters is wrong (according to M$). Try: .AdvancedFilter($xlFilterInPlace, $oExcel.Sheets("FILTRE_ELABORE").Range("A1:A2"), "", false ) 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 Link to comment Share on other sites More sharing options...
jahjah Posted March 1, 2011 Author Share Posted March 1, 2011 Ok thanks a lot for your answer, i'll try that and give you news Link to comment Share on other sites More sharing options...
jahjah Posted March 2, 2011 Author Share Posted March 2, 2011 Thanks you to all of you for the helpI choose the function 'ill userIt's will be _excelFilterI tried it but i've got this error messageC:\Program Files\AutoIt3\Include\Excel_udf.au3 (31) : ==> The requested action with this object has failed.:$oExcel.selection.Autofilter($sField, $sCriteria)$oExcel.selection.Autofilter($sField, $sCriteria)^ ERRORHere is my script, but i made some changeFor resume it want to Enter a word to search in a excel fil fot that i use GUICtrlCreateInputMake a research with Find (that it's ok)After i want to filter my file with the variable enter in GUICtrlCreateInput-------------------------------------------The resaerch is ok but i cannot made the filterplease find in attachement my scripttestscriptpreskeok.au3 Link to comment Share on other sites More sharing options...
jahjah Posted March 3, 2011 Author Share Posted March 3, 2011 Hi, My script working but i still need some help The excelfilter function working but not well I cannot filter all my file when i filter i still have the other row i want only the row i want appear. While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE MsgBox(0, "Rachel_Search", "Merci de votre visite") ExitLoop ;When button is pressed, label text is changed ;to combobox value Case $msg = $Button1 $menustate = GUICtrlRead($Input1) Chercher() Filtre($menustate) EndSelect WEnd Exit Func Chercher() Local $search_cell = $oExcel.Columns("A:G").Find($menustate) If( IsObj($search_cell) = 1 ) Then ; Si la recherche à abouti MsgBox(0, "Find success", "La recherche de "&Chr(34)&$menustate&Chr(34)&" dans la plage donne la cellule ("&$search_cell.Row &";"&$search_cell.Column&")" ) Else MsgBox(0, "Find failed", "La recherche de "&Chr(34)&$menustate&Chr(34)&" dans la plage n'a rien donné" ) EndIf EndFunc Func Filtre($find) _ExcelFilter ($oExcel,5,3,3,($find)) EndFunc Link to comment Share on other sites More sharing options...
jahjah Posted March 4, 2011 Author Share Posted March 4, 2011 I found the solution. Thanks again 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