Jump to content

Excel RangeFind is not working


Recommended Posts

Hey there! 😃

I am having a problem with the _Excel_RangeFind. I am trying to search for a value in a particular cell range. The script copies the value from the internet. Copying and saving as a variable is working fine, but as soon as it should find the value in excel, nothing happens. ( I am not getting an error)

#include <Excel.au3>
   
   Func Excel()
    Send("{CTRLDOWN}")
    Send("{c}")
    Send("{CTRLUP}")
    Local $sName = ClipGet() ;Text
    Local $sShortName = StringTrimRight ( $sName, 1) ;delete one letter
    Local $bOpenWorkBook = False, $oExcel = _Excel_Open()
    Local $sFilePath = "C:\Users\Acer\OneDrive\xyz.xlsx"
    Local $oWorkbook
    $oWorkbook = _Excel_BookAttach($sFilePath)
    If @error Then
      $oWorkbook = _Excel_BookOpen($oExcel, $sFilePath)
      $bOpenWorkBook = True
    EndIf
    sleep(15000)
    Send("{LWINDown}") 
    Send ("{up}") ;maximize window
    Send("{LWINup}") 
    sleep(1000)
    _Excel_RangeFind ($oWorkbook, $sShortName, "A3:A56")
   EndFunc

Is anyone familiar with this problem or am I just missing some basic stuff? 

Thanks for help!

Link to comment
Share on other sites

_Excel_RangeFind returns either a 2D Array of the results or error (see help file for return values).  Use _ArrayDisplay (requires #include <Array.au3> to show you the results.  Also try to use ControlSend rather than Send, Send can have be unpredictable, whereas ControlSend is targeted and less likely to have any issues.

Link to comment
Share on other sites

Link to comment
Share on other sites

35 minutes ago, Nine said:

To make your script more robust, you can use excel method instead of using Send to maximize the window like this :

Const $xlMaximized = -4137
$oExcel.WindowState = $xlMaximized

 

Thanks! I included your suggestion in my script 🙂

Link to comment
Share on other sites

7 hours ago, Subz said:

_Excel_RangeFind returns either a 2D Array of the results or error (see help file for return values).  Use _ArrayDisplay (requires #include <Array.au3> to show you the results.  Also try to use ControlSend rather than Send, Send can have be unpredictable, whereas ControlSend is targeted and less likely to have any issues.

Hey Subz

Thank you very much for helping me once again! I replaced the send() with the ControlSend() and added the Array.

Is is possible to let the RangeFind show the result by switching to it/ making it the active cell? (like ctrl+f in excel) Because I would like to RangeRead it afterwards. If it is showed in an array, I don't know how the RangeRead could work. 

Thank you again for the productive support!

Link to comment
Share on other sites

Link to comment
Share on other sites

I strongly suggest to not mix the Excel UDF (uses COM to interact with Excel) and GUi automation like Send, ControlSend etc.
Most (if not all) things you can do with GUI automation can be done using COM. But COM does not interfere with the user and is much easier to debug.
Just my 2 cents worth ;)
 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

1 hour ago, Subz said:

What happens if you have multiple results?  Either way you would just use the array[x][2] to get the address of the cell that was found.

How?

In my case, there can not be multiple results since the range find is searching for numbers from A3 to A56. These cells only contain a numberation from 1 to 50. 

The problem I am facing right now is, that the script should run by itself, without me having to click away the _ArrayDisplay window. Is the rangefind executed and the therefore the array safed, even if I don't use _ArrayDisplay?

What I am trying right now is transforming the RangeFind array result (see screenshot) into a variable using the  _Arraytostring. (does that work like that?) I have problems creating a string only of "col 2" and "row 0" value.

local $sSuchergebnis = _Excel_RangeFind ($oWorkbook, $sNummername, "A3:A56")
   sleep(1000)
   local $sfinal = _Arraytostring($sSuchergebnis, 0, 0, 2, 2)

and then I would use the function Nine sugguested:

$oWorkBook.ActiveSheet.Range ($sfinal).Activate

to activite the cell.

Appreciate your support!

arraydisplay.png

Link to comment
Share on other sites

Link to comment
Share on other sites

But I think he tries to automate the GUI again by activating the found cell. Using _Excel_RangeCopyPaste is the way I'd suggest.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...