title: Powershell script for Excel error code
body: <p>I'm trying to convert an Excel .xls file that has several worksheets into a .csv with Powershell 4.0. I know the SaveAs in the for each loop isn't phrased right, and that the error is pointing to line 17 and character 9, I just don't know how to fix it or how to interpret the error code 0x800A03EC.</p>
  
  <p>Here's the script:</p>
  
  <pre class="lang-psh prettyprint-override"><code>Function ExportWSToCSV ($inputWorkbookPath, $outputFilePrefix, $outputDirectory)
  {
  
      #Start Excel invisibly without pop-up alerts.
      $inputWorkbookPath = "R:\Unclaimed Property\NC State\Jun 2015\" + `
                           "NC_RAW_JUL1986thruMAR2013" + ".xls"
  
      $excel = New-Object -ComObject Excel.Application
      $excel.Visible = $false
      $excel.DisplayAlerts = $false
  
      #Open Excel file.
      $workBook = $excel.Workbooks.Open($inputWorkbookPath) 
  
      foreach ($workSheet in $workBook.Worksheets)
      {
          $n = $inputWorkbookPath + "_" + $workSheet.Name
          $workSheet.SaveAs($outputDirectory + $n + ".csv", 6)
      }
      $excel.Quit()
  }
  
  ExportWSToCSV -inputWorkbookPath "R:\Unclaimed Property\NC State\Jun 2015\NC_RAW_JUL1986thruMAR2013.xls" `
                -outputFilePrefix "output_" `
                -outputDirectory "R:\Unclaimed Property\NC State\Jun 2015\"
  </code></pre>
  
  <p>Here's the error:</p>
  
  <pre class="lang-psh prettyprint-override"><code>Exception calling "SaveAs" with "2" argument(s): "Exception from    HRESULT: 0x800A03EC"
  At \\ncdfs1\documents$\ANDREWN\My Documents\PSscript_for_NC.ps1:17   char:9
  +         $workSheet.SaveAs($outputDirectory + $n + ".csv", 6)
  +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : NotSpecified: (:) [],  MethodInvocationException
  + FullyQualifiedErrorId : ComMethodTargetInvocation
  </code></pre>