title: VBA Macro to run PowerShell Command
body: <p>I am trying to create a macro, that would be able to rename all files with ".docx" extension in a folder.</p>
  
  <p>The PowerShell command works when used directly, but when used through the VBA code, it's not executing.</p>
  
  <pre class="lang-vb prettyprint-override"><code>Sub test()
      Dim retval
      Dim pscmd
  
      pscmd = "PowerShell -ExecutionPolicy Bypass -Command ""Get-ChildItem -Path *.docx -Recurse | Rename-Item -NewName {$_.Name.Substring(0,7) + $_.Extension }"""
  
      retval = Shell(pscmd, vbNormalFocus)
  
      Debug.Print pscmd
  End Sub
  </code></pre>
  
  <p>The script is executing without compilation errors, but the files are not being renamed.</p>
  
  <p>What do I need to change?</p>