Jump to content

_Excel_RangeFind in a specific sheet


Recommended Posts

The third param specify the range.  Something like this :

#include <Excel.au3>

Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, @MyDocumentsDir & "\Test.xls")

Local $aResult = _Excel_RangeFind($oWorkbook, "Test", $oWorkbook.sheets(2).usedRange)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "RangeFind Error", @error & "/" & @extended)
_ArrayDisplay($aResult)

 

Link to post
Share on other sites

@kawumm3000
You could use Worksheets collection to search in a specific sheet:

#include <Array.au3>
#include <Excel.au3>

Test()

Func Test()

    Local $strFileName = @ScriptDir & "\Test.xlsx", _
          $objExcel, _
          $objWorkbook, _
          $arrResult


    $objExcel = _Excel_Open()
    If @error Then Return ConsoleWrite("_Excel_Open ERR: " & @error & @CRLF)

    $objWorkbook = _Excel_BookOpen($objExcel, $strFileName)
    If @error Then Return ConsoleWrite("_Excel_BookOpen ERR: " & @error & @CRLF)

    ; Use $objWorkbook.Worksheets(SheetNumber).UsedRange or $objWorkbook.Worksheets(SheetName).UsedRange
    $arrResult = _Excel_RangeFind($objWorkbook, "TextToFind", $objWorkbook.Worksheets(1).UsedRange)
    If @error Then Return ConsoleWrite("_Excel_RangeFind ERR: " & @error & @CRLF)

    If UBound($arrResult) > 0 Then _ArrayDisplay($arrResult)

    _Excel_BookClose($objWorkbook)
    _Excel_Close($objExcel)

EndFunc

@Nine :D

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...