i trying use excel advanced filter through powershell not having luck.i can use autofilter running following code:
$rangetofilter = $worksheet2.usedrange.select $excel.selection.autofilter(2,"testfilter") however, don't understand how convert syntax given here http://msdn.microsoft.com/en-us/library/office/bb209640(v=office.12).aspx powershell accept. example, i've tried
$excel.selection.advancedfilter("xlfilterinplace","","","true") but following error:
exception calling "advancedfilter" "4" argument(s): "advancedfilter method of range class failed" @ line:1 char:32 + $excel.selection.advancedfilter <<<< ("xlfilterinplace","","","true") + categoryinfo : notspecified: (:) [], methodinvocationexception + fullyqualifiederrorid : commethodtargetinvocation so there way run excel advanced filter through powershell?
edit -- found this: http://gallery.technet.microsoft.com/scriptcenter/57b497a4-d634-44c6-be5c-ba2699f9961a/ not working...
none of arguments advancedfilter() string.
object advancedfilter( xlfilteraction action, object criteriarange, object copytorange, object unique ) the first enumeration. in vba can use directly because there implicitly global. not in powershell, have reference them explicitly qualified names:
$xlfilterinplace = [microsoft.office.interop.excel.xlfilteraction]::xlfilterinplace the other 3 arguments typed object, means of variant type in com. however, #2 , #3 supposed range objects, bets off if pass in else.
they marked optional. optional parameters should have no value represented the missing type in .net com interop. again, in powershell have reference explicitly:
$missing = [type]::missing argument #4 supposed boolean, pass powershell bool constant (or, since parameter optional well, $missing).
$excel.selection.advancedfilter($xlfilterinplace, $missing, $missing, $true)
Comments
Post a Comment