none
VB Script to Convert RTF to MS Word 2010 Docx - Compatibility Mode Issue RRS feed

  • Question

  • Hi there,

    I have the following script that takes all RTFs in a folder and converts them to Word's Docx. The script works but all the files open up in compatibility mode. Is there anyway to change the script to remove this problem? I've posted this in the Word section but no one there has been able to help. My script is:

    Dim oWord, oDoc, fso, f
    Set oWord = CreateObject("Word.Application")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder("C:\MyDir")
    For Each file In f.Files
    If Right(LCase(file.Name), 4) = ".rtf" Then
    Set oDoc = oWord.Documents.Open(file.Path)
    oDoc.SaveAs Left(file.Path, Len(file.Path) - 4) & ".docx", wdFormatDocumentDefault, _
    CompatibilityMode=14
    End If
    Next
    fso.DeleteFile("C:\MyDir\*.rtf"), DeleteReadOnly
    oWord.Quit
    Set oWord = Nothing
    Set fso = Nothing

    Any help really, really appreciated!

    cheers

    Steve

    • Moved by Bill_Stewart Sunday, December 29, 2013 2:56 PM Moving to more appropriate forum
    Thursday, August 22, 2013 9:24 PM

All replies

  • Your VBScript example is impossible.  Have you actually tried to run it?

    ¯\_(ツ)_/¯

    Thursday, August 22, 2013 9:45 PM
  • Try it this way:
    Set oWord = CreateObject("Word.Application")
    oWord.Visible=True
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder("C:\scripts\doctest")
    
    For Each file In f.Files
    	If Right(LCase(file.Name), 4) = ".rtf" Then
    		Set oDoc = oWord.Documents.Open(file.Path)
    		newname = Replace(file.Path,".rtf",".doc")
    		MsgBox newname
    		oDoc.SaveAs newname
    		oDoc.Close 
    		fso.DeleteFile file.Path,True
    	End If
    Next
    
    oWord.Quit
    


    ¯\_(ツ)_/¯

    Thursday, August 22, 2013 10:28 PM
  • Hiya,

    Yes I have run my script and it runs perfectly but the file created always opens in Compatibility Mode. The format I need it in is Word 2010 so having a .docx extension.

    I tried your script and it converts files fine to doc but when I tried putting in docx it corrupted the file - any ideas?

    cheers

    Steve

    Thursday, August 22, 2013 10:47 PM
  • Set oWord = CreateObject("Word.Application")
    oWord.Visible=True
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder("C:\scripts\doctest")
    
    For Each file In f.Files
    	If Right(LCase(file.Name), 4) = ".rtf" Then
    		Set oDoc = oWord.Documents.Open(file.Path)
    		newname = Replace(file.Path,".rtf",".docx")
    		oDoc.SaveAs newname,12
    		oDoc.Close 
    		'fso.DeleteFile file.Path,True
    	End If
    Next
    
    oWord.Quit
    
    The documentation is wrong.

    ¯\_(ツ)_/¯

    Thursday, August 22, 2013 11:09 PM
  • Hiya,

    Script works well but still opening up in Compatibility Mode in Word 2010. I tried different enumerations and all gave the same result. Is it possible to get rid of it?

    cheers and thanks for your help so far

    Steve

    Thursday, August 22, 2013 11:38 PM
  • I have no idea what you are talking about.  Compatibility mode is a setting of Word and no of a document.

    You should post questions about Word in the Word forum.


    ¯\_(ツ)_/¯

    Thursday, August 22, 2013 11:42 PM
  • What I'm after is for the script to save the rtf as a native Word 2010 file. In other words when the file opens up it comes up with no compatibility issues as it's a proper Word 2010 document.

    Your script works and is more elegant than mine but both have the issue above.

    Thursday, August 22, 2013 11:46 PM