0

I have not been able to make work this simple command $Range.Find($SearchString,LookAt:=xlWhole)

It returns syntax error. Without LookAt works fine, but I need exact match

Matt
  • 45,022
  • 8
  • 78
  • 119
LiRU
  • 1
  • 1

1 Answers1

0

PowerShell does not use VBA syntax. That is why you are getting an error. Also, you need to define the parameters you are skipping in place of their defaults in your Excel method calls. This is done with [Type]::Missing as you have discovered.

As far as using the enum for LookAt on of the simple things you can do is use the integer representation. 1 in this case is for xlWhole.

If you don't want to use magic number you can define your own constants with a simple variable

$xlWhole = 1

You can, in a way, use the actual constant if you add the assembly that contains these constants.

Add-Type -Assembly 'Microsoft.Office.Interop.Excel'
$Range.Find($SearchString,[Type]::Missing,[Type]::Missing,[Microsoft.Office.Interop.Excel.XlLookAt]::xlWhole)‌​
Matt
  • 45,022
  • 8
  • 78
  • 119