title: Converting word documents to excel with VBscript
body: <p>I'm building a tool in VBscript that would convert all of the word documents in a folder into excel documents. I need to copy everything and keep the source formatting. This works manually by ctrl-a the word document and paste to the excel document. The main problem is with ActiveDocument (i'm unsure if it's activating my word document) and i'm unsure how to do the paste to the excel document. </p>
  
  <p>Here is my code so far. It makes new excel files with the same name as the word documents, but it doesn't copy the contents and paste.</p>
  
  <pre><code>set shApp = CreateObject("shell.application")
  currentPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") 
  set shFolder = shApp.NameSpace( currentPath )
  set files = shFolder.Items()
  
  
  
  for each files in files
      if files.type = "Microsoft Word 97 - 2003 Document" OR files.type = "Microsoft Word Document" then
        msgbox("Converting: "&amp;files.path)
        Call DocConvert() 'function call to function that converts .doc to .xls
  
  end if
  next
  
  
  'Opens a word document copies the contents and pastes it into an excel document of the same name
  Function DocConvert()
  
   On Error Resume Next
  
   Set objWord = GetObject(, "Word.Application")
          If Err &lt;&gt; 0 Then
              Set objWord = CreateObject("Word.Application")
          End If
  
   objWord.Visible = True
   objWord.Documents.Open(files.path)
  
   ActiveDocument.Range(0, 0).Select
   Selection.WholeStory
   Selection.Copy
  
  
   Set objExcel = CreateObject("Excel.Application")
   objExcel.Visible = True
   Set objWorkbook = objExcel.Workbooks.Add()
  
   ExcelSave = replace(files.path,"doc","xls")
  
   objWorkbook.SaveAs(ExcelSave)
  
   objWord.Quit
   objExcel.Quit
  
  End Function
  </code></pre>