-
Posts
192 -
Joined
-
Last visited
Everything posted by MichaelHB
-
Hi tuffgong, I like to split the actions in functions, your while loop for example: _CheckServer("server") ; PING server in a loop. Will not proceed until successfull PING or will exit if timeout _CreateIE() GUIDelete() Exit Func _CreateIE($hTimeout = 120000) ;2 min default timeout Local $hTimer = TimerInit() While TimerDiff($hTimer) < $hTimeout Global $oIE = _IECreate("http://server/app", 1, 0) ; open an invisible instance of IE If @error Or Not IsObj($oIE) Then While ProcessExists("iexplore.exe") And TimerDiff($hTimer) < $hTimeout ProcessClose("iexplore.exe") WEnd Sleep(5000) ContinueLoop EndIf With $oIE ; set properties for page - makes page visible .Left = 0 .Top = 0 .MenuBar = True .Resizable = False .StatusBar = False .TheaterMode = False .Toolbar = True .Fullscreen = False .Visible = True EndWith Local $hWnd = _IEPropertyGet($oIE, "hwnd") If Not @error And IsHWnd($hWnd) Then Do WinSetState($hWnd, "", @SW_MAXIMIZE) ; maximize web page If TimerDiff($hTimer) > $hTimeout Then ExitLoop 2 Until Sleep(1000) And BitAND(WinGetState($hWnd), 32) Else Do WinSetState("Quality Control - Internet Explorer", "", @SW_MAXIMIZE) ; maximize web page If TimerDiff($hTimer) > $hTimeout Then ExitLoop 2 Until Sleep(1000) And BitAND(WinGetState("Quality Control - Internet Explorer"), 32) EndIf Return WEnd Exit MsgBox(0,"Timeout","Could not create IE object.") EndFunc ;==>_CreateIE Func _CheckServer($sAddress, $hTimeout = 300000) ;5 min default timeout Local $hTimer = TimerInit() Do If TimerDiff($hTimer) > $hTimeout Then Exit MsgBox(0,"Timeout","Server not responding.") Until Sleep(3000) And Ping($sAddress) EndFunc ;==>_CheckServer
-
catching downloads in an IE object
MichaelHB replied to MattHiggs's topic in AutoIt General Help and Support
@orbs, what kind of automation in IE download you are looking for (start/stop/resume)? Also, did you try my example in #9? If you really want to click and use the build in download manager in IE, you can easily use UI Automation to "open" / "save" / "saveas" / "cancel" etc, then you can open the download manager (ctrl+j) and get some limited information. Now if you are talking about COM access you can build your own IE Custom Download Manager, i found these example (never tested myself). -
catching downloads in an IE object
MichaelHB replied to MattHiggs's topic in AutoIt General Help and Support
@MattHiggs, try this example: #include <InetConstants.au3> #include <IE.au3> Global $bDownloadFinished = False ExampleStart() Exit Func ExampleStart() Local $oIE = _IECreate("www.ninite.com") Local $oIEEvents = ObjEvent($oIE, "_IEEvent_", "DWebBrowserEvents2") If Not IsObj($oIEEvents) Then Exit ConsoleWrite("Error in $oIEEvents" & @CRLF) $aInputElements = _IEquerySelectorAll($oIE, 'ul[class ="list-unstyled center-block js-masonry"] input, body > div > form', -1) If @error Or Not IsArray($aInputElements) Then Exit ConsoleWrite("Error in $aInputElements" & @CRLF) For $i = 1 To UBound($aInputElements)-1 ConsoleWrite($aInputElements[$i].value & @CRLF) $aInputElements[$i].checked = True Next _IEFormSubmit($aInputElements[0]) If @error Then Exit ConsoleWrite("Error in _IEFormSubmit. Error code: " & @error & @CRLF) While Not $bDownloadFinished Sleep(100) WEnd MsgBox(0,0,"Done!") EndFunc ;==>ExampleStart Func _IEquerySelectorAll(ByRef $oObject, $sQuery, $iIndex = 0) If Not __IEIsObjType($oObject, "browserdom") Then __IEConsoleWriteError("Error", "_IEquerySelectorAll", "$_IESTATUS_InvalidObjectType", ObjName($oObject)) Return SetError($_IESTATUS_InvalidObjectType, 0, 0) ElseIf Not IsInt($iIndex) Or Not ($iIndex > -2) Then __IEConsoleWriteError("Error", "_IEquerySelectorAll", "$_IEStatus_InvalidValue", "Invalid Index") Return SetError($_IEStatus_InvalidValue, 0, 0) EndIf Local $oCol = __IEIsObjType($oObject, "documentcontainer") ? $oObject.document.querySelectorAll($sQuery) : $oObject.querySelectorAll($sQuery) If @error Then __IEConsoleWriteError("Error", "_IEquerySelectorAll", "$_IESTATUS_COMError", @error) Return SetError($_IESTATUS_COMError, 0, 0) ElseIf Not IsObj($oCol) Then __IEConsoleWriteError("Error", "_IEquerySelectorAll", "$_IESTATUS_InvalidObjectType", "Invalid Object") Return SetError($_IESTATUS_InvalidObjectType, 0, 0) ElseIf $oCol = Null Or $oCol.length = 0 Then __IEConsoleWriteError("Error", "_IEquerySelectorAll", "$_IEStatus_NoMatch") Return SetError($_IEStatus_NoMatch, 0, 0) ElseIf $iIndex >= $oCol.length Then __IEConsoleWriteError("Error", "_IEquerySelectorAll", "$_IEStatus_InvalidValue", "$iIndex > Nº of elements found") Return SetError($_IEStatus_InvalidValue, 0, 0) EndIf If $iIndex = -1 Then Local $aColReturn[$oCol.length] For $i = 0 To $oCol.length - 1 $aColReturn[$i] = $oCol.Item($i) Next Return SetError($_IEStatus_Success, $oCol.length, $aColReturn) Else Return SetError($_IEStatus_Success, $oCol.length, $oCol.Item($iIndex)) EndIf EndFunc ;==>_IEquerySelectorAll Func _IEEvent_BeforeNavigate2($oIEpDisp, $sIEURL, $iIEFlags, $sIETargetFrameName, $sIEPostData, $iIEHeaders, $bIECancel) ConsoleWrite(@CRLF & "!!!!--BeforeNavigate2 fired--!!! --> " & "$sIEURL = " & $sIEURL) If StringInStr($sIEURL, "ninite.exe") Then ConsoleWrite(@CRLF & @CRLF & "--> Download STARTED --> " & $sIEURL & @CRLF) Local $sFilePath = @TempDir & "\niniteTEST.exe" ; Download the file in the background with the selected option of 'force a reload from the remote site.' Local $hDownload = InetGet($sIEURL, $sFilePath, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) ; Wait for the download to complete by monitoring when the 2nd index value of InetGetInfo returns True. Do Sleep(250) Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE) ; Retrieve the number of total bytes received and the filesize. Local $iBytesSize = InetGetInfo($hDownload, $INET_DOWNLOADREAD) Local $iFileSize = FileGetSize($sFilePath) ; Close the handle returned by InetGet. InetClose($hDownload) ; Display details about the total number of bytes read and the filesize. ConsoleWrite("Donwload path: " & $sFilePath & @CRLF) ConsoleWrite("The total download size: " & $iBytesSize & " | The total filesize: " & $iFileSize & @CRLF) ConsoleWrite("--> Download FINISHED -->" & $sIEURL & @CRLF & @CRLF) $bDownloadFinished = True EndIf EndFunc ;==>_IEEvent_BeforeNavigate2 Exit @mLipok, i dont know any options to disable the save dialog in IE 11. Some interesting references, thanks, i'll play with them later. -
catching downloads in an IE object
MichaelHB replied to MattHiggs's topic in AutoIt General Help and Support
As i can see the urls are build like this: https://ninite.com/7zip-peazip-winrar/ninite.exe [3 applications] https://ninite.com/7zip-evernote-googleearth-peazip-winrar/ninite.exe [5 applications] Did you try to build them (urls) and download with the native autoit functions? Your issue is not that complicated, as i told you in #2 you can listen to the browser events and take proper action, the download "popup" can also be automated (you can grab the control info in the autoit window info). -
catching downloads in an IE object
MichaelHB replied to MattHiggs's topic in AutoIt General Help and Support
Hi MattHiggs, I do not know if I got right your intent (not a native english), but you can monitor the "BeforeNavigate" event then read urls (take any action if you want to) and use the "DownloadBegin" and "DownloadComplete" events to make a proper check. There is an exemple in the helpfile under the "ObjEvent" function that shows how to use the "BeforeNavigate2" event. -
ildary, The problem is that the function _IEAttach is failing, so $oIE is not an object. See if this is what you want: #include <IE.au3> For $iOpenNew = 0 To 1 If $iOpenNew = 0 Then Local $oIE1 = _IECreate("www.google.com", 0, 1, 0) Else Local $oIE2 = _IENavigate2($oIE1, "www.google.com", 1, 2048) MsgBox(0,0,"Check if there is another google tab.") _IENavigate2($oIE2, "www.autoitscript.com") EndIf Next MsgBox(0,0,"Done!") Exit Func _IENavigate2(ByRef $oObject, $sUrl, $iWait = 1, $BrowserNavFlag = 0) #cs $BrowserNavFlags: Default is 0, navigate in the same window. navOpenInNewWindow = 1 navNoHistory = 2 navNoReadFromCache = 4 navNoWriteToCache = 8 navAllowAutosearch = 16 navBrowserBar = 32 navHyperlink = 64 navEnforceRestricted = 128 navNewWindowsManaged = 256 navUntrustedForDownload = 512 navTrustedForActiveX = 1024 navOpenInNewTab = 2048 navOpenInBackgroundTab = 4096 navKeepWordWheelText = 8192 navVirtualTab = 16384 navBlockRedirectsXDomain = 32768 navOpenNewForegroundTab = 65536 #ce If Not __IEIsObjType($oObject, "documentContainer") Then If @error = $_IESTATUS_InvalidDataType Then __IEConsoleWriteError("Error", "_IENavigate", "$_IESTATUS_InvalidDataType") Return SetError($_IESTATUS_InvalidDataType, 1, 0) Else __IEConsoleWriteError("Error", "_IENavigate", "$_IESTATUS_InvalidObjectType") Return SetError($_IESTATUS_InvalidObjectType, 1, 0) EndIf EndIf ; If $BrowserNavFlag Then Local $iRandom = Random(10001, 99999, 1), $oIE, $iNotifyStatus, $hTimer = TimerInit() $oObject.Navigate2("about:blank-" & $iRandom, $BrowserNavFlag) If @error Then ; Trap COM error, report and return __IEConsoleWriteError("Error", "_IENavigate", "$_IESTATUS_COMError", @error) Return SetError($_IESTATUS_ComError, @error, 0) EndIf $iNotifyStatus = _IEErrorNotify() _IEErrorNotify(False) While Not IsObj($oIE) Sleep(500) $oIE = _IEAttach("about:blank-" & $iRandom, "URL") If TimerDiff($hTimer) > 30000 Then _IEErrorNotify($iNotifyStatus) __IEConsoleWriteError("Error", "_IENavigate", "", "Time out. TimerDiff > 30000ms") Return SetError(1, 0, 0) EndIf WEnd _IEErrorNotify($iNotifyStatus) $oIE.Navigate2($sUrl) If @error Then ; Trap COM error, report and return __IEConsoleWriteError("Error", "_IENavigate", "$_IESTATUS_COMError", @error) Return SetError($_IESTATUS_ComError, @error, 0) EndIf If $iWait Then _IELoadWait($oIE) Return SetError(@error, 0, $oIE) EndIf Return SetError($_IESTATUS_Success, 0, $oIE) EndIf ; $oObject.Navigate2($sUrl) If @error Then ; Trap COM error, report and return __IEConsoleWriteError("Error", "_IENavigate", "$_IESTATUS_COMError", @error) Return SetError($_IESTATUS_ComError, @error, 0) EndIf ; If $iWait Then _IELoadWait($oObject) Return SetError(@error, 0, -1) EndIf Return SetError($_IESTATUS_Success, 0, -1) EndFunc ;==>_IENavigate
-
Control autoit from internet (web page)
MichaelHB replied to rony2006's topic in AutoIt General Help and Support
Would not be better to download a already done free app? Threre are free options that could serve your needs, just google "free remote connection for mobile devices" or something like this, no need to build a script to do that. This could also interest you: As you need a really fast solution to monitor your puppies, just download one of the free software that you can easly find. -
Control autoit from internet (web page)
MichaelHB replied to rony2006's topic in AutoIt General Help and Support
Why not a remote connection (there is some UDFs and free apps online) to lauch the the script with the function to turn the lights on. -
Help needed with IE automation
MichaelHB replied to pranaynanda's topic in AutoIt GUI Help and Support
Sure. I asked because i was making some modifications for a friend and they can be implemented in the IE. Like: IECreate with command-line options (‑noframemerging for example, use regread to find the ie installation and PID for the IEAttach method). IENavigate with NavFlags like: navOpenInBackgroundTab I have a querySelectorAll function that is already working fine (with the same standard of other IE functions). very useful func if i may add. There is some redundancies, for example IsObj is checked twice in most functions (the other time is in __IEIsObjType). All the objects colletions should return an array with the objects. For nodecolletion is not recommended the For-In-Next loop, so using an array is 5x times faster than element.item($i), and its at least 2x faster for HtmlElementCollection. This is what i remember right know, i believe that there is more. The tests that i made is in the initals steps and i have not had the opportunity to test on multiple systems. -
Help needed with IE automation
MichaelHB replied to pranaynanda's topic in AutoIt GUI Help and Support
@mLipok, if i may ask an off topic question, do you think that would be interesting to improve some IE UDF functions (even add a new one)? Is there any restrictions to change or suggest modifications in this UDF? -
find first instance of valid date in listview
MichaelHB replied to gcue's topic in AutoIt General Help and Support
You can also change the way that you populate the groups. Making it in a way you dont need to worry about the item order in the array, then no matter order, you will always bel able to set the right group order with different numbers of elements. -
find first instance of valid date in listview
MichaelHB replied to gcue's topic in AutoIt General Help and Support
I'm no expert, but maybe in this way you dont need to worry if the groups have the same number of items. #include <Date.au3> #include <Array.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) Local $array[21][2] $array[0][0] = "lemon" $array[0][1] = "Group 1" $array[1][0] = "03/2/201111" $array[1][1] = "Group 1" $array[2][0] = "candy" $array[2][1] = "Group 1" $array[3][0] = "ship" $array[3][1] = "Group 2" $array[4][0] = "2013/05/12 03:12:22" $array[4][1] = "Group 2" $array[5][0] = "ants" $array[5][1] = "Group 2" $array[6][0] = "2011/04/09 11:34:02" $array[6][1] = "Group 3" $array[7][0] = "34/23" $array[7][1] = "Group 3" $array[8][0] = "pasta" $array[8][1] = "Group 3" $array[9][0] = "chilli" $array[9][1] = "Group 4" $array[10][0] = "12/12" $array[10][1] = "Group 4" $array[11][0] = "1999/03/14 09:19:34" $array[11][1] = "Group 4" $array[12][0] = "1989/01/20 01:01:56" $array[12][1] = "Group 5" $array[13][0] = "melon" $array[13][1] = "Group 5" $array[14][0] = "1989/01/20 01:01:56" $array[14][1] = "Group 5" $array[15][0] = "water" $array[15][1] = "Group 6" $array[16][0] = "staple" $array[16][1] = "Group 6" $array[17][0] = "brocolli" $array[17][1] = "Group 6" $array[18][0] = "corn" $array[18][1] = "Group 7" $array[19][0] = "1989/12/01 02:21:19" $array[19][1] = "Group 7" $array[20][0] = "1989/12" $array[20][1] = "Group 7" $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE) $iExListViewStyle = BitOR($LVS_REPORT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_DOUBLEBUFFER, $LVS_EX_CHECKBOXES) GUICreate("EXAMPLE") $idListview = GUICtrlCreateListView("Item", 2, 2, 398, 398, -1, $iExWindowStyle) _GUICtrlListView_SetColumnWidth($idListview, 0, 250) _GUICtrlListView_SetExtendedListViewStyle($idListview, $iExListViewStyle) ; Add items & Build groups _GUICtrlListView_EnableGroupView($idListview) Local $iCurrentGroup, $iLastCreatedGroup For $i = 0 To UBound($array)-1 _GUICtrlListView_AddItem($idListview, $array[$i][0]) $iCurrentGroup = Number(StringReplace($array[$i][1], "Group ", "")) If $iCurrentGroup <> $iLastCreatedGroup Then _GUICtrlListView_InsertGroup($idListview, -1, $iCurrentGroup, $array[$i][1]) $iLastCreatedGroup = $iCurrentGroup EndIf _GUICtrlListView_SetItemGroupID($idListview, $i, $iCurrentGroup) Next Local $iGroupCount = _GUICtrlListView_GetGroupCount($idListview) Local $bFirstDateIsValidFound, $aGroupIndex, $sItemText For $i = 1 To $iGroupCount $bFirstDateIsValidFound = False $aGroupIndex = _ArrayFindAll($array, "Group " & $i, Default, Default, Default, Default, 2) If Not @error And IsArray($aGroupIndex) Then For $j = 0 To UBound($aGroupIndex) - 1 $sItemText = $array[$aGroupIndex[$j]][0] If (_DateIsValid($sItemText) And Not $bFirstDateIsValidFound) Or (($j = (UBound($aGroupIndex) - 1)) And Not $bFirstDateIsValidFound) Then $bFirstDateIsValidFound = True ContinueLoop EndIf _GUICtrlListView_SetItemChecked($idListview, $aGroupIndex[$j]) Next EndIf Next GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit1") GUISetState() While 1 Sleep(100) WEnd Func _Exit1() Exit EndFunc Exit -
Choosing An Element From _UIA_getObjectByFindAll
MichaelHB replied to Debremus's topic in AutoIt General Help and Support
Try this: _UIA_getObjectByFindAll($oOBJ,"controltype:=" & $UIA_TableControlTypeId & ";indexrelative:=2", $treescope_subtree) -
Help needed with IE automation
MichaelHB replied to pranaynanda's topic in AutoIt GUI Help and Support
pranaynanda, Here the example: #include <IE.au3> Local $oIE = _IECreate("https://www.facebook.com") _IELoadWait($oIE) If @error Then $oIE = _IEAttach("facebook.com", "url") If @error Then Exit ConsoleWrite("Error in _IEAttach" & @CRLF & "@error: " & @error) EndIf Local $oEmail = _IEGetObjById($oIE, "email") If @error Then Exit ConsoleWrite("Error in $oEmail" & @CRLF & "@error: " & @error) _IEFormElementSetValue($oEmail, "email@email.com") If @error Then Exit ConsoleWrite("Error in _IEFormElementSetValue($oEmail)" & @CRLF & "@error: " & @error) Local $oPassword = _IEGetObjById($oIE, "pass") If @error Then Exit ConsoleWrite("Error in $oPassword" & @CRLF & "@error: " & @error) _IEFormElementSetValue($oPassword, "password") If @error Then Exit ConsoleWrite("Error in _IEFormElementSetValue($oPassword)" & @CRLF & "@error: " & @error) Local $oSubmit = _IEGetObjById($oIE, "u_0_m") If @error Then Exit ConsoleWrite("Error in $oSubmit" & @CRLF & "@error: " & @error) MsgBox(0, "", "Before click on submit button.") _IEAction($oSubmit, "click") If @error Then Exit ConsoleWrite('Error in _IEAction($oSubmit, "click")' & @CRLF & "@error: " & @error) MsgBox(0, "", "Done!") Exit As state by Danp2, _IECreate automatically performs an _IELoadWait by default but as you are getting an error (-2147417848) probably because your browser is internally "jumping" to a different security zone, so because i dont know if you are using a COM error handler, the _IELoadWait will error out (i believe this way will be easier for you to understand) and try to _IEAttach. You can easily adapt this example to fit your needs. -
Help needed with IE automation
MichaelHB replied to pranaynanda's topic in AutoIt GUI Help and Support
pranaynanda, Did you try the IE UDF? -
Regarding Checkbox in IE Browser protected mode...
MichaelHB replied to shalini's topic in AutoIt GUI Help and Support
Did you read the link that i provided (the information is very clear with you first study and understand the regkey autoit functions) ? Did you understand what is a "regkey" (Windows Registry) ? Let me see what have you tried with the examples in the helpfile that is not working. I already gave you the answer to always select CHECKED in that checkbox using a "ControlCommand", did you tried? -
Regarding Checkbox in IE Browser protected mode...
MichaelHB replied to shalini's topic in AutoIt GUI Help and Support
shalini, There is better ways to automate this task (i would go for change regkey - here can give you a start). I know that if you have no clue how to do it in autoit you will need some time to learn and you can start reading the helpfile about regkeys, you could start with "RegRead" function. In the meanwhile you can change your last line [Send("{SPACE}")] for this: ControlCommand(WinGetHandle("Internet Options"), "", "Button3", "Check", "") Remeber that the title (Internet Options) is in english and may change if you have a different language in you system, also use the Autoit Window Info to confirm the control class. Also you can change all your "Send" functions for the "Control...", this is a better way to automate this window. -
Regarding Checkbox in IE Browser protected mode...
MichaelHB replied to shalini's topic in AutoIt GUI Help and Support
Hi shalini, Can you explain better what is not working and show us some code to help understand what are you doing? From what i could understand you want to keep the protected mode checkbox CHECKED, and when its already CHECKED (you are probably doing some click) its gets UNCHECKED, am i right? This is the control you want to keep CHECKED? -
Find location of cell that contains specific text
MichaelHB replied to Laurynelis's topic in AutoIt General Help and Support
True, and both functions (_Excel_Open / _Excel_BookOpen) should not hang the script. I cant reproduce the OP issue, but when he used the ObjGet by path it worked for him. The difference in both cases were ObjCreate and ObjGet by class and the CLSID of the Workbook in the _Excel_BookAttach function and those should not freeze the script . -
Find location of cell that contains specific text
MichaelHB replied to Laurynelis's topic in AutoIt General Help and Support
Laurynelis, The array returned by the function ($aResult) already gives you the sheet name in its first column, all you need is to first the results you want. If you want restrict the search to a specific sheet you will need to modify the function. I belive that is easier to filter the array as its gives the information that you want. -
Find location of cell that contains specific text
MichaelHB replied to Laurynelis's topic in AutoIt General Help and Support
Laurynelis, Thanks for let me know. Glad that solved your problem. @water, i dont have a win 10 to test but i think Laurynelis problem could be related to the "$sCLSID_Workbook" (_Excel_BookAttach), for some reason it get stuck in the While loop (it should gives an error when it reaches an invalid instance). I dont see any problems in my win 7. -
Find location of cell that contains specific text
MichaelHB replied to Laurynelis's topic in AutoIt General Help and Support
Try this: #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include <Array.au3> #include <Excel.au3> Local $sValueToFind = "lol" Local $sFileOpenDialog = FileOpenDialog("Please select the Excel file", "", "Excel (*.xlsx;*.xlsm;*.xlsb;*.xltx;*.xltm;*.xls;*.xlt;*.xml)", BitOR($FD_FILEMUSTEXIST, $FD_PATHMUSTEXIST)) If @error Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.") ConsoleWrite($sFileOpenDialog & @CRLF) ShellExecute($sFileOpenDialog, "", "", "open", @SW_MAXIMIZE) If @error Then Exit MsgBox(0, "ERROR", "Error in ShellExecute") Local $aExcelFileName = StringRegExp($sFileOpenDialog, '[^\\]*$', 1) If Not IsArray($aExcelFileName) Then Exit MsgBox(0, "ERROR", "Error in StringRegExp" & @CRLF & "@error: " & @error) If Not WinWait($aExcelFileName[0], "", 15) Then Exit MsgBox(0, "ERROR", "Error in WinWait") Sleep(3000) Local $oWorkbook = ObjGet($sFileOpenDialog) If @error Or Not IsObj($oWorkbook) Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error in ObjGet") Local $aResult = __Excel_RangeFind($oWorkbook, $sValueToFind) If Not @error And IsArray($aResult) Then _ArrayDisplay($aResult, "Excel UDF: _Excel_RangeFind Example", "", 0, "|", "Sheet|Cell|Value|Formula") Exit Else Exit MsgBox(0, "Error", "The value/text (" & $sValueToFind & ") could not be found.") EndIf Func __Excel_RangeFind($oWorkbook, $sSearch, $vRange = Default, $iLookIn = Default, $iLookAt = Default, $bMatchcase = Default) If Not IsObj($oWorkbook) Or ObjName($oWorkbook, 1) <> "_Workbook" Then Return SetError(1, 0, 0) If StringStripWS($sSearch, 3) = "" Then Return SetError(2, 0, 0) If $iLookIn = Default Then $iLookIn = $xlValues If $iLookAt = Default Then $iLookAt = $xlPart If $bMatchcase = Default Then $bMatchcase = False Local $oMatch, $sFirst = "", $bSearchWorkbook = False, $oSheet If $vRange = Default Then $bSearchWorkbook = True $oSheet = $oWorkbook.Sheets(1) $vRange = $oSheet.UsedRange ElseIf IsString($vRange) Then $vRange = $oWorkbook.Activesheet.Range($vRange) If @error Then Return SetError(3, @error, 0) EndIf Local $aResult[100][4], $iIndex = 0, $iIndexSheets = 1, $iNumberOfSheets = $oWorkbook.Worksheets.Count While 1 $oMatch = $vRange.Find($sSearch, Default, $iLookIn, $iLookAt, Default, Default, $bMatchcase) If @error Then Return SetError(4, @error, 0) If IsObj($oMatch) Then $sFirst = $oMatch.Address While 1 $aResult[$iIndex][0] = $oMatch.Worksheet.Name $aResult[$iIndex][1] = $oMatch.Address $aResult[$iIndex][2] = $oMatch.Value $aResult[$iIndex][3] = $oMatch.Formula $iIndex = $iIndex + 1 If Mod($iIndex, 100) = 0 Then ReDim $aResult[UBound($aResult, 1) + 100][4] $oMatch = $vRange.Findnext($oMatch) If Not IsObj($oMatch) Or $sFirst = $oMatch.Address Then ExitLoop WEnd EndIf If Not $bSearchWorkbook Then ExitLoop $iIndexSheets = $iIndexSheets + 1 If $iIndexSheets > $iNumberOfSheets Then ExitLoop $sFirst = "" $oSheet = $oWorkbook.Sheets($iIndexSheets) If @error Then ExitLoop $vRange = $oSheet.UsedRange WEnd ReDim $aResult[$iIndex][4] Return $aResult EndFunc Exit -
Find location of cell that contains specific text
MichaelHB replied to Laurynelis's topic in AutoIt General Help and Support
@Laurynelis Try this example with your test.xlsx file, this code works for me. #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include <Array.au3> #include <Excel.au3> Local $sValueToFind = "lol" Local $sFileOpenDialog = FileOpenDialog("Please select the Excel file", "", "Excel (*.xlsx;*.xlsm;*.xlsb;*.xltx;*.xltm;*.xls;*.xlt;*.xml)", BitOR($FD_FILEMUSTEXIST, $FD_PATHMUSTEXIST)) If @error Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.") ConsoleWrite($sFileOpenDialog & @CRLF) ShellExecute($sFileOpenDialog, "", "", "open", @SW_MAXIMIZE) If @error Then Exit MsgBox(0, "ERROR", "Error in ShellExecute") Local $aExcelFileName = StringRegExp($sFileOpenDialog, '[^\\]*$', 1) If Not IsArray($aExcelFileName) Then Exit MsgBox(0, "ERROR", "Error in StringRegExp" & @CRLF & "@error: " & @error) If Not WinWait($aExcelFileName[0], "", 15) Then Exit MsgBox(0, "ERROR", "Error in WinWait") Sleep(3000) Local $oWorkbook = _Excel_BookAttach($aExcelFileName[0], "FileName") If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error opening workbook '" & $sFileOpenDialog & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $aResult = __Excel_RangeFind($oWorkbook, $sValueToFind) If Not @error And IsArray($aResult) Then _ArrayDisplay($aResult, "Excel UDF: _Excel_RangeFind Example", "", 0, "|", "Sheet|Cell|Value|Formula") Exit Else Exit MsgBox(0, "Error", "The value/text (" & $sValueToFind & ") could not be found.") EndIf Func __Excel_RangeFind($oWorkbook, $sSearch, $vRange = Default, $iLookIn = Default, $iLookAt = Default, $bMatchcase = Default) If Not IsObj($oWorkbook) Or ObjName($oWorkbook, 1) <> "_Workbook" Then Return SetError(1, 0, 0) If StringStripWS($sSearch, 3) = "" Then Return SetError(2, 0, 0) If $iLookIn = Default Then $iLookIn = $xlValues If $iLookAt = Default Then $iLookAt = $xlPart If $bMatchcase = Default Then $bMatchcase = False Local $oMatch, $sFirst = "", $bSearchWorkbook = False, $oSheet If $vRange = Default Then $bSearchWorkbook = True $oSheet = $oWorkbook.Sheets(1) $vRange = $oSheet.UsedRange ElseIf IsString($vRange) Then $vRange = $oWorkbook.Activesheet.Range($vRange) If @error Then Return SetError(3, @error, 0) EndIf Local $aResult[100][4], $iIndex = 0, $iIndexSheets = 1, $iNumberOfSheets = $oWorkbook.Worksheets.Count While 1 $oMatch = $vRange.Find($sSearch, Default, $iLookIn, $iLookAt, Default, Default, $bMatchcase) If @error Then Return SetError(4, @error, 0) If IsObj($oMatch) Then $sFirst = $oMatch.Address While 1 $aResult[$iIndex][0] = $oMatch.Worksheet.Name $aResult[$iIndex][1] = $oMatch.Address $aResult[$iIndex][2] = $oMatch.Value $aResult[$iIndex][3] = $oMatch.Formula $iIndex = $iIndex + 1 If Mod($iIndex, 100) = 0 Then ReDim $aResult[UBound($aResult, 1) + 100][4] $oMatch = $vRange.Findnext($oMatch) If Not IsObj($oMatch) Or $sFirst = $oMatch.Address Then ExitLoop WEnd EndIf If Not $bSearchWorkbook Then ExitLoop $iIndexSheets = $iIndexSheets + 1 If $iIndexSheets > $iNumberOfSheets Then ExitLoop $sFirst = "" $oSheet = $oWorkbook.Sheets($iIndexSheets) If @error Then ExitLoop $vRange = $oSheet.UsedRange WEnd ReDim $aResult[$iIndex][4] Return $aResult EndFunc Exit