none
Converting Files RRS feed

Answers

  • I want to convert a batch of WORD documents to the RTF format; how do I do this?

    This will do the trick

    Sub SaveAsRTF()
        Dim sDoc As Document
        Dim myFolder As String, myFile As String
        myFolder = Application.FileDialog(msoFileDialogFolderPicker)
        With Application.FileDialog(msoFileDialogFolderPicker)
            .AllowMultiSelect = False
            .Show
            If .SelectedItems.Count > 0 Then
                myFolder = .SelectedItems(1)
            End If
        End With
        myFile = Dir(myFolder & "\*.docx") '
        Do While myFile <> ""
            Set sDoc = Application.Documents.Open(myFolder & "\" & myFile)
            sDoc.SaveAs2 FileName:=Replace(sDoc.Name, ".docx", ""), FileFormat:=wdFormatRTF
            sDoc.Close
            myFile = Dir
        Loop
    End Sub
    

    Tuesday, February 17, 2015 4:47 PM
  • First of all, the current forum is for developers. I'd suggest asking non-programming questions on the Word IT Pro Discussions forum instead.

    It is not clear what Word documents files you need to convert -.doc or .docx. Also there is no information about where and when you need to run the code.

    You can use automation to run word programmatically and save the required files using the RTF format. See How to automate Microsoft Word to create a new document by using Visual C# for more information.

    Also you may consider using third-party controls/components - RadRichTextBox and Aspose.Words for .NET .

    Tuesday, February 17, 2015 4:49 PM
  • John,

    The code will not work on the server-side or from any unattended client. The Considerations for server-side Automation of Office article states the following:

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

    Fei,

    It is not clear the details where the asker is going to use solution. Please refer to my previous post for more information.

    Wednesday, February 18, 2015 8:56 AM

All replies

  • I want to convert a batch of WORD documents to the RTF format; how do I do this?

    This will do the trick

    Sub SaveAsRTF()
        Dim sDoc As Document
        Dim myFolder As String, myFile As String
        myFolder = Application.FileDialog(msoFileDialogFolderPicker)
        With Application.FileDialog(msoFileDialogFolderPicker)
            .AllowMultiSelect = False
            .Show
            If .SelectedItems.Count > 0 Then
                myFolder = .SelectedItems(1)
            End If
        End With
        myFile = Dir(myFolder & "\*.docx") '
        Do While myFile <> ""
            Set sDoc = Application.Documents.Open(myFolder & "\" & myFile)
            sDoc.SaveAs2 FileName:=Replace(sDoc.Name, ".docx", ""), FileFormat:=wdFormatRTF
            sDoc.Close
            myFile = Dir
        Loop
    End Sub
    

    Tuesday, February 17, 2015 4:47 PM
  • First of all, the current forum is for developers. I'd suggest asking non-programming questions on the Word IT Pro Discussions forum instead.

    It is not clear what Word documents files you need to convert -.doc or .docx. Also there is no information about where and when you need to run the code.

    You can use automation to run word programmatically and save the required files using the RTF format. See How to automate Microsoft Word to create a new document by using Visual C# for more information.

    Also you may consider using third-party controls/components - RadRichTextBox and Aspose.Words for .NET .

    Tuesday, February 17, 2015 4:49 PM
  • John,

    The code will not work on the server-side or from any unattended client. The Considerations for server-side Automation of Office article states the following:

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

    Fei,

    It is not clear the details where the asker is going to use solution. Please refer to my previous post for more information.

    Wednesday, February 18, 2015 8:56 AM
  • John,

    The code will not work on the server-side or from any unattended client. The Considerations for server-side Automation of Office article states the following:

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

    Fei,

    It is not clear the details where the asker is going to use solution. Please refer to my previous post for more information.

    Hi Eugene,

    I did not really notice that this thread was under VSTO. I just knew it was under Office for Developers, which also includes VBA solutions. I am not sure what the scope of the original poster is. But the subroutine does work, it provides a quick and dirty solution to save all Word files in a selected folder to RTF format. It also provides a framework for an application-level Word add-in.

    John

    Wednesday, February 18, 2015 5:59 PM
  • Hi JLWellberg

    As you can see from the responses you've received, no one is sure what, exactly, you want to do. If you are NOT looking for a programming solution then the suggestion to ask in the Word IT Pro forum is a good one. Microsoft has often provided batch converter utilities as part of the tools for Office administrators. Whether these are available for you will depend on the version of Office available. The folks in the IT Pro forum will know...


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, February 18, 2015 9:01 PM
    Moderator