title: PowerShell Run Macro with dynamic parameter
body: <p>I'm trying to execute some macros though my powershell in a dynamic way. I receive a dictionary with macro names and parameters and need to execute it. </p>
  
  <p>This is the code.</p>
  
  <p>Imagine that in <code>$ParamContent</code> I have the following variables: <code>"Param 1"+'#'+"Param 2"+'#'+"Param 3"</code> </p>
  
  <pre class="lang-bsh prettyprint-override"><code>$arguments = $MacroName + "'"
  
  $ParamContent = $MacroParams.Split("{#}")
  
  for ($i=0; $i -lt $ParamContent.count;$i++) {
      #$arguments += ",'" + $ParamContent[$i] + "'"
      $arguments += ",'" + $ParamContent[$i] + "'"
  }
  
  $arguments = $arguments.Substring(0,$arguments.Length-1)
  write-host $arguments
  
  $xl.run.Invoke($arguments)
  </code></pre>
  
  <p>The actual error is the following:</p>
  
  <blockquote>
    <p>System.Management.Automation.MethodInvocationException: Exception
    calling "Run" with "31" argument(s): "Cannot run the macro
    'Connections.openConnThroughParameters','RMDeriv','RMDeriv_uat','UAT'.
    The macro may not be available in this workbook or all macros may be
    disabled." ---> System.Runtime.InteropServices.COMException: Cannot
    run the macro
    'Connections.openConnThroughParameters','RMDeriv','RMDeriv_uat','UAT'.
    The macro may not be available in this workbook or all macros may be
    disabled. System.Runtime.InteropServices.COMException: Cannot run the
    macro 'Connections.openConnThroughParameters','Param 1','Param
    2','Param 3'. The macro may not be available in this workbook or all
    macros may be disabled</p>
  </blockquote>