title: Pass variable from PowerShell to VBA macro?
body: <p>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.</p>
  
  <p>Is it possible to pass this criteria from PowerShell into the macro? I could then just have the 1 macro.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>$counts = $workbook.worksheets.item(2)
  $xRows = $counts.cells.item(1,1).Text
  $yeRows = $counts.cells.item(1,2).Text
  </code></pre>
  
  <p>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.</p>
  
  <p>Any suggestions?</p>