0

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?

3
  • 1
    You wouldn't pass "xlValues", "xlWhole", "xlByRows" as a string - each of these has a corresponding value - e.g msdn.microsoft.com/en-us/vba/excel-vba/articles/… Commented Aug 2, 2018 at 19:58
  • And I think you'd use [Type]::Missing instead of $null - stackoverflow.com/questions/17483483/… Commented Aug 2, 2018 at 20:14
  • Thank you, both answers combined were able to point me in the right direction, many ways to slice this problem aparrently Commented Aug 2, 2018 at 20:17

1 Answer 1

0

From Range.Find - note that xlValues, xlWhole, and xlByRows are not referred to as Strings, 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: -4163
  • xlWhole: 1
  • xlByRows: 1

Note also that you should use [Type]::Missing instead of $null, as this answer suggests.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.