title: Run script file from Excel VBA and pass variable to the script file
body: <p>I have a code that enables me to execute the Windows script file (PowerShell script file) and the code works fine with no problems.</p>
  
  <p>What I am trying to do is to pass a variable to a line in the script file.
  Example:</p>
  
  <p>This line in the script file</p>
  
  <pre class="lang-bsh prettyprint-override"><code>convert Image.png -resize 300x300 -density 300 -quality 100 ImageNew.png
  </code></pre>
  
  <p>The line has the <code>Image.png</code> but this file name I would like it to be variable and passes a value to it through Excel cell.
  In other words I have the file name in a cell and I would like to change <code>Image.png</code> to be the value in the cell.</p>
  
  <p>This is the script file:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>cd (Join-Path $env:USERPROFILE 'Desktop\Output\')
  convert Image.png -resize 300x300 -density 300 -quality 100 ImageNew.png
  </code></pre>
  
  <p>And this is the VBA code I am using:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Sub TestMe()
      MsgBox ScriptFile
  End Sub
  
  Function ScriptFile() As String
      Dim wshShell   As Object
      Dim strCommand As String
  
      strCommand = "Powershell.exe -File ""C:\Users\Future\Desktop\Sample.ps1"""
      Set wshShell = CreateObject("WScript.Shell")
      wshShell.Run strCommand, 0, True
  End Function
  </code></pre>
  
  <p>Any idea how to do that?</p>
  
  <p>I tried so far
  In VBA Code I used this line</p>
  
  <pre><code>strCommand = "Powershell.exe -File ""&amp; {'C:\Users\Future\Desktop\Sample.ps1' 001.png}"""
  </code></pre>
  
  <p>and in the script file I used this line at the top</p>
  
  <pre><code>$image=$args[0]
  </code></pre>
  
  <p>But I couldn't make it work yet</p>