I have a PowerShell script that automates some report processing, and I have numerous separate macros to perform very similar autofilter functions, but on different criteria.
Is it possible to pass this criteria from PowerShell into the macro? I could then just have the 1 macro.
ColNum = Application.Match("*header", Range("A1:Z1"), 0)
If Not IsError(ColNum) Then
ActiveSheet.Range("A1").AutoFilter Field:=ColNum, Criteria1:="$criterafromPowerShell", Operator:=xlAnd
End If
I currently do a similar thing but the other way round, the output from these macros I insert to the workbook and extract back to PowerShell like so:
$counts = $workbook.worksheets.item(2)
$xRows = $counts.cells.item(1,1).Text
$yeRows = $counts.cells.item(1,2).Text
I concede I could possibly do this the other way round, and insert the text I want to use in a worksheet after the file is opened and before the macros are run, then pick it up inside the macro... but it seems messy.
Any suggestions?
Application.Runmethod. - I think....Run()method is part of the Excel App class so you would do something like$xlApp.Run("'myWorkbook.xlsm'!Module1.MyUDF()", $arg1, $arg2)- Syntax may not be correct but should give you an idea of what I'm saying