I need to do a case insensitive search in an Excel document using Range.Find.
I'm currently using the following command as an attempt do a case insensitive search for any email address returned by https://haveibeenpwned.com
$Found = $WorkSheet.Cells.Find($SearchText, $null, "xlValues", "xlWhole", "xlByRows", 1, $false) #What, After, Lookin, LookAt, SearchOrder, MatchCase
It returns:
WARNING: [] No public exploits found!
Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))
At C:\Users\qqqq\Documents\incidents\Search-PwnAddress.ps1:31 char:9
+ $Found = $WorkSheet.Cells.Find($SearchText, $null, "xlValues" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
How do I properly do a Range Find so that I can do a case insensitive search?
From Range.Find - note that xlValues
, xlWhole
, and xlByRows
are not referred to as String
s, but constants. They are members of specific Enumerations
- the XlFindLookIn
, XlLookAt
and XlSearchOrder
enumerations.
Enumerations have members with descriptive names that reference a specific value - so in this case, you can use the corresponding value as your argument. Trying to pass their names as Strings
- i.e. "xlValues"
- will throw a "Type Mismatch" error.
xlValues
: -4163xlWhole
: 1xlByRows
: 1Note also that you should use [Type]::Missing
instead of $null
, as this answer suggests.
User contributions licensed under CC BY-SA 3.0