title: vbs macro Method Run of object 'IWshShell3' failed only chokes on larger Word files
body: <p>I am really new to VBA. I've pasted only the last part of this sub, but can put the rest up if it helps.  Would appreciate any assist.  I've searched for days, but most issues with this error are caused by spaces in the path name.  Thank you extra!</p>
  
  <p>This macro reads the header, then each table in the open Word document, then writes each line to the <code>htmlFile</code> variable.  It then runs the PowerShell ps1 file that writes the HTML file to the save path.</p>
  
  <p>Works great on smaller Word docs, but when i run it on a larger ones, i get this error:</p>
  
  <blockquote>
    <p>Run-time error '-2147024690 (800700ce)': Method 'Run' of object
    'IwshShell3' failed</p>
  </blockquote>
  
  <p>Code (Everything in the Sub before this bit was reading each table in the open Word doc and writing to <code>htmlFile</code> as HTML code):</p>
  
  <pre class="lang-vb prettyprint-override"><code>Sub WriteHtml()
      Dim htmlFile AS String, strText As String
  
      '
      ' fill htmlFile with HTML code ...
  
      htmlFile = htmlFile &amp; strText
  
      Dim pwFileLocation, htmlFileLocation As String
      pwFileLocation = "'O:\Docketbk\DocketToWeb\processFile.ps1'"
  
      'htmlFileLocation = "'W:" &amp; stringSplits(1) &amp; "'"
      htmlFileLocation = "'Q:\OIT\Web Sites\This Site\Regulatory\Docketbk\" &amp; stringSplits(1) &amp; "'"
      fileNameFinal = Left(ActiveDocument.Name, InStrRev(ActiveDocument.Name, ".") - 1) &amp; ".html"
  
      Dim shell, command1
      command1 = "powershell -noexit -command powershell.exe -Executionpolicy Bypass -File " &amp; pwFileLocation &amp; "-htmlContent ""'" &amp; htmlFile &amp; """' -savePath " &amp; htmlFileLocation &amp; " -fileName """ &amp; fileNameFinal &amp; """"
      Set shell = CreateObject("WScript.Shell")
      shell.Run command1, 1
  
  End Sub
  </code></pre>
  
  <p>POWERSHELL CODE:</p>
  
  <pre><code>param(
     [string] $htmlContent,
     [string] $savePath,
     [string] $fileName
  )
  $fullFilePath = $savePath + "\" + $fileName 
  
  Function CreateHtmlFile()
  {
          if (!(Test-Path -Path $fullFilePath)){
              New-Item  $fullFilePath -ItemType File
              WriteHtmlFile       
          } else {
               WriteHtmlFile
          }
  }
  Function WriteHtmlFile()
  {
          Set-Content $fullFilePath $htmlContent.Replace('$DubQ','"')     
  }
  createHtmlFile
  </code></pre>
  
  <p>POWERSHELL MOVE CODE:</p>
  
  <pre><code>param(
     [string] $oldFileLocation,
     [string] $newFileLocation
  )
  
  net use W: \\MYSERVERNAME\Websites\PUC\Regulatory\Docketbk
  
  Function MoveFile
  {
      $moveDirectory = $oldFileLocation + "/*" 
      Copy-Item -Path $MoveDirectory  -Destination $newFileLocation -Container -Recurse -force
  }
  
  MoveFile
  </code></pre>