none
save word 2010 as 2003 RRS feed

  • Question

  • I have word files (.docx) that i want to save as .doc format can any one point me how to do this ? I dont want to open each and every file and save as ------

    by far this is the code I got :

    Dim strFilename As String
    Dim strPath As String
    Dim oDoc As Document
    Dim fDialog As FileDialog
    Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
    
    With fDialog
        .Title = "Folder Browser Select folder and click OK"
        .AllowMultiSelect = False
        .InitialView = msoFileDialogViewList
        If .Show <> -1 Then
            MsgBox "Operation Cancelled ", , _
                   "SPreparation"
            Exit Sub
        End If
        strPath = fDialog.SelectedItems.Item(1)
        If Right(strPath, 1) <> "\" _
           Then strPath = strPath + "\"
    End With
    
    If Documents.Count > 0 Then
        Documents.Close SaveChanges:=wdPromptToSaveChanges
    End If
    If Left(strPath, 1) = Chr(34) Then
        strPath = Mid(strPath, 2, Len(strPath) - 2)
    End If
    strFilename = Dir$(strPath & "*.docx?")
    
    While Len(strFilename) <> 0
        WordBasic.DisableAutoMacros 1
        Set oDoc = Documents.Open(strPath & strFilename)
        '
        'The Code to be executed as Batch is  Inserted Below
    
    
    MsgBox ("Saving as 2003 Format")
    
    
    oDoc.Close SaveChanges:=wdSaveChanges, FileFormat:=wdFormatDocument97
        WordBasic.DisableAutoMacros 0
        strFilename = Dir$()
    Wend
    MsgBox ("Operation Successfully Done")

    but no success , any help ???????

    Saturday, August 3, 2013 12:15 PM

All replies

  • As far as I'm aware, the only way to save a file in a different format for any Office program is to open and save as. This is much easier if all files are in the same folder as you can then loop thru all such files and save a copy in a new format in a subdirectory.

    If files are in many different folders, you need a list of all files and their full paths somewhere to iterate through.


    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    Saturday, August 3, 2013 9:07 PM
  • You need a minor modification to your code for it to work, but there is no alternative to opening, saving and closing each document. If you don't want to retain the original you would need to include code to remove it after saving it with the new name. See below

    Dim strFilename As String
    Dim strOldName As String
    Dim strPath As String
    Dim oDoc As Document
    Dim fDialog As FileDialog
        Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

        With fDialog
            .Title = "Folder Browser Select folder and click OK"
            .AllowMultiSelect = False
            .InitialView = msoFileDialogViewList
            If .Show <> -1 Then
                MsgBox "Operation Cancelled ", , _
                       "SPreparation"
                Exit Sub
            End If
            strPath = fDialog.SelectedItems.Item(1)
            If Right(strPath, 1) <> "\" _
               Then strPath = strPath + "\"
        End With

        If Documents.Count > 0 Then
            Documents.Close SaveChanges:=wdPromptToSaveChanges
        End If
        If Left(strPath, 1) = Chr(34) Then
            strPath = Mid(strPath, 2, Len(strPath) - 2)
        End If
        strFilename = Dir$(strPath & "*.doc?")

        While Len(strFilename) <> 0
            WordBasic.DisableAutoMacros 1
            Set oDoc = Documents.Open(strPath & strFilename)
            strOldName = oDoc.FullName
            strFilename = Left(strFilename, InStrRev(strFilename, ".")) & "doc"
            oDoc.SaveAs Filename:=strPath & strFilename, _
                        FileFormat:=wdFormatDocument97, _
                        AddToRecentFiles:=False
            oDoc.Close SaveChanges:=wdDoNotSaveChanges
            WordBasic.DisableAutoMacros 0
            'Kill strOldName 'Optionally removes the docx version. Use with care as it is not reversible.
            strFilename = Dir$()
        Wend
        MsgBox ("Operation Successfully Done")


    Graham Mayor - Word MVP
    www.gmayor.com

    Sunday, August 4, 2013 5:40 AM