none
VB Script to Convert RTF to MS Word 2010 Docx 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?

    Any help gratefully received.The script is called from another program (SAS) and deletes once finished:

    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
    fso.DeleteFile(Wscript.ScriptFullName)
    Set fso = Nothing
    

    regards

    Steve

    Thursday, August 15, 2013 11:15 PM

All replies

  • Hiya,

    Thanks for this but really looking to do it in the script. Reports go out nationwide and IT wont remove the compatibility mode.

    SAVEAS2 seems to have the commands I need but I cant get it to work?

    Tuesday, August 20, 2013 8:02 PM
  • Which version of Word are you running the script on?

    Please describe HOW SAveAs2 isn't working.

    Note that the basic *.docx file format is the same for Word 2007, 2010 and 2013. It has been extended for each new version, so files created for an older version will open fine in a later version, but show "Compatibility Mode". The instruction for the older version must be in the files' RTF.

    One possiblity would be to let your code execute as it's doing. Afterwards, use the Open XML SDK to simply change this setting in the document structure (done without the Word application). See http://blogs.msmvps.com/wordmeister/2013/01/18/openxmlsdk-word-compatibility-mode/


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, August 21, 2013 10:29 AM
    Moderator
  • Hi Cindy,

    Thank you for this. The rtf file is created using SAS software and then I get SAS to execute the VB script to convert these to Word 2010.

    Can you think of any way I can get the script to save the the file in native Word 2010 ie not open in compatibility mode?

    Every time I try using the SaveAs2 it throws up an error about expecting statement where the filename is which I'm taking to mean it is looking for a filename in quotes?

    To be honest I'm just after a script that works ie that I can point at a directory of rtf files and will convert them all to Word 2010 docx files. I've searched the net far and wide and have had no luck at all.

    Any help really appreciated.

    cheers
    Steve

    Wednesday, August 21, 2013 9:24 PM
  • I'm not familiar with SAS so I can't offer you any help with how it works.

    You'd have to show me the exact error message you get with SaveAs2, as well as the code as you're trying to use it. The information you provide is insufficient. Certainly, though, you must provide a string as a file name, no matter which method you use, but you appear to be doing that...

    <<To be honest I'm just after a script that works ie that I can point at a directory of rtf files and will convert them all to Word 2010 docx files. I've searched the net far and wide and have had no luck at all.>>

    I doubt there are "scripts" laying around for that, although there are conversion tools. You might ask in the IT Pro forum on TechNet what IT administrators are using. And there's always Word Automation Services (part of SharePoint) which performs exactly this kind of task.


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, August 22, 2013 3:20 PM
    Moderator