| 1 | #include <Excel.au3>
|
|---|
| 2 | #include <Array.au3>
|
|---|
| 3 |
|
|---|
| 4 | ; AutoIT 3.3.12.0 (Production), tested with Excel 2007.
|
|---|
| 5 | ;
|
|---|
| 6 | ; _Excel_RangeFind test file
|
|---|
| 7 | ;
|
|---|
| 8 | ; Testing search functionality by searching for strings in and across sheets.
|
|---|
| 9 |
|
|---|
| 10 | ; Create Excel object
|
|---|
| 11 | Local $oExcel = _Excel_Open()
|
|---|
| 12 |
|
|---|
| 13 | ; Create two new sheets, both with one sheet each.
|
|---|
| 14 | Local $oBookNumbers = _Excel_BookNew($oExcel, 1)
|
|---|
| 15 | Local $oBookLetters = _Excel_BookNew($oExcel, 1)
|
|---|
| 16 |
|
|---|
| 17 | ; Populate sheets with data.
|
|---|
| 18 | For $i = 1 To 100
|
|---|
| 19 | $oBookNumbers.Sheets(1).Range("A" & String($i)).Value = $i
|
|---|
| 20 | $oBookLetters.Sheets(1).Range("A" & String($i)).Value = _Excel_ColumnToLetter($i)
|
|---|
| 21 | Next
|
|---|
| 22 |
|
|---|
| 23 | ; Define search results variable
|
|---|
| 24 | Local $search
|
|---|
| 25 |
|
|---|
| 26 | MsgBox(0, "Active sheet", "The following four searches search the active sheet. These work as expected.")
|
|---|
| 27 |
|
|---|
| 28 | ; Set the active sheet to the sheet with numbers...
|
|---|
| 29 | $oBookNumbers.Sheets(1).Activate
|
|---|
| 30 |
|
|---|
| 31 | ; These searches will work just fine.
|
|---|
| 32 | $search = _Excel_RangeFind($oBookNumbers, "42", "A1:A100")
|
|---|
| 33 | _ArrayDisplay($search, """42"" on active sheet (numbers) with range as string")
|
|---|
| 34 | $search = _Excel_RangeFind($oBookNumbers, "42", $oBookNumbers.Sheets(1).Range("A1:A100"))
|
|---|
| 35 | _ArrayDisplay($search, """42"" on active sheet (numbers) with range as object")
|
|---|
| 36 |
|
|---|
| 37 | ; Set the active sheet to the one with letters...
|
|---|
| 38 | $oBookLetters.Sheets(1).Activate
|
|---|
| 39 |
|
|---|
| 40 | ; Once again, both of these searches should also work fine.
|
|---|
| 41 | $search = _Excel_RangeFind($oBookLetters, "AF", "A1:A100")
|
|---|
| 42 | _ArrayDisplay($search, """AF"" on active sheet (letters) with range as string")
|
|---|
| 43 | $search = _Excel_RangeFind($oBookLetters, "AF", $oBookLetters.Sheets(1).Range("A1:A100"))
|
|---|
| 44 | _ArrayDisplay($search, """AF"" on active sheet (letters) with range as object")
|
|---|
| 45 |
|
|---|
| 46 | MsgBox(0, "Cross-sheet", "The following four searches search the inactive book. The first and third fail, but do not return errors.")
|
|---|
| 47 |
|
|---|
| 48 | ; Set the active sheet to the one with letters...
|
|---|
| 49 | $oBookLetters.Sheets(1).Activate
|
|---|
| 50 |
|
|---|
| 51 | ; Despite each book only having one sheet, the string search fails if the search sheet is not active.
|
|---|
| 52 | $search = _Excel_RangeFind($oBookNumbers, "42", "A1:A100")
|
|---|
| 53 | _ArrayDisplay($search, """42"" on numbers sheet with range as string. Failed search")
|
|---|
| 54 | $search = _Excel_RangeFind($oBookNumbers, "42", $oBookNumbers.Sheets(1).Range("A1:A100"))
|
|---|
| 55 | _ArrayDisplay($search, """42"" on numbers sheet with range as object")
|
|---|
| 56 |
|
|---|
| 57 | ; Set the active sheet to the one with numbers...
|
|---|
| 58 | $oBookNumbers.Sheets(1).Activate
|
|---|
| 59 |
|
|---|
| 60 | ; Same thing with searching numbers.
|
|---|
| 61 | $search = _Excel_RangeFind($oBookLetters, "AF", "A1:A100")
|
|---|
| 62 | _ArrayDisplay($search, """AF"" on letters sheet with range as string. Failed search")
|
|---|
| 63 | $search = _Excel_RangeFind($oBookLetters, "AF", $oBookLetters.Sheets(1).Range("A1:A100"))
|
|---|
| 64 | _ArrayDisplay($search, """AF"" on letters sheet with range as object")
|
|---|