none
Converting Multiple Documents RRS feed

  • Question

  • Good Afternoon Everyone,

    We recently updated to Office 2007 and we have many documents we use over and over. We are looking for a way to take the documents (419) and convert them from .doc to .docx without having to open them. I manually did 10 to make sure formatting would be good and it is. Any great ideas?


    Chris Ward
    Monday, October 31, 2011 7:16 PM

Answers

  • If you place all documents in a single folder, you could run this macro:

     

    Sub ConvertDoc2Docx()
        Dim strPath As String
        Dim strFile As String
        Dim doc As Document
        With Application.FileDialog(4) ' msoFileDialogFolderPicker
            If .Show Then
                strPath = .SelectedItems(1)
            Else
                MsgBox "You didn't select a folder. Exiting...", vbInformation
                Exit Sub
            End If
        End With
        Application.ScreenUpdating = False
        If Right(strPath, 1) <> "\" Then
            strPath = strPath & "\"
        End If
        strFile = Dir(strPath & "*.doc")
        Do While strFile <> ""
            Set doc = Documents.Open(FileName:=strPath & strFile, _
                AddToRecentFiles:=False)
            doc.SaveAs FileName:=strPath & strFile & "x", _
                FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
            doc.Close SaveChanges:=False
            strFile = Dir
        Loop
        Application.ScreenUpdating = True
    End Sub
    


    Warnings:

    • The code will fail if it encounters a password-protected document.
    • Since .docx cannot store macros, you'll have problems if there are documents that contain macros.

    Do you have a pressing need to convert? Word 2007 can open and save Word 97-2003 documents (.doc) without problems. 


    Regards, Hans Vogelaar
    • Marked as answer by KCDW Tuesday, November 1, 2011 6:57 PM
    Monday, October 31, 2011 9:50 PM
  • You can create the macro in a Word document or template. For example:

    • Start Word.
    • Press Alt+F11 to activate the Visual Basic Editor.
    • Select Insert | Module to create a new module.
    • Copy/paste the ConvertDoc2Docx macro into the module.
    • Switch back to Word.
    • Save the document as a macro-enabled document (.docm) in a folder that is designated as a trusted location.
    • Whenever you want to convert a bunch of documents in a folder, open this document, then press Alt+F8 to display the Macros dialog. Select ConvertDoc2Docx and click Run.

    Regards, Hans Vogelaar
    • Marked as answer by KCDW Tuesday, November 1, 2011 6:57 PM
    Tuesday, November 1, 2011 5:43 PM
  • 1) No idea where a .doxx file would come from. Sorry...

    2) That should work.

    3) I'd expect the password prompt to be displayed.


    Regards, Hans Vogelaar
    • Marked as answer by KCDW Tuesday, November 1, 2011 6:57 PM
    Tuesday, November 1, 2011 6:40 PM
  • How about

    doc.SaveAs FileName:=strPath &"converted docx\" & strFile & "x", _
                 FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
     
    


    Regards, Hans Vogelaar
    • Marked as answer by KCDW Tuesday, November 1, 2011 7:43 PM
    Tuesday, November 1, 2011 7:28 PM
  • Hans,

    This works very well, thank you.

    1) In addition to creating the docx, another file is created for each file doxx. Is this a backup of the original?

    2) Can you specify a new folder location for the converted files? Just put a folder in the current =strpath (converted docx) as

        Do While strFile <> ""
            Set doc = Documents.Open(FileName:=strPath & strFile, _
                AddToRecentFiles:=False)
            doc.SaveAs FileName:=strPath &"\converted docx" & strFile & "x", _
                FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
            doc.Close SaveChanges:=False
            strFile = Dir
        Loop

    3) Can there be a prompt for password so that I can enter the password instead of it failing?


    Chris Ward
    • Marked as answer by KCDW Tuesday, November 1, 2011 6:57 PM
    Tuesday, November 1, 2011 6:16 PM

All replies

  • If you place all documents in a single folder, you could run this macro:

     

    Sub ConvertDoc2Docx()
        Dim strPath As String
        Dim strFile As String
        Dim doc As Document
        With Application.FileDialog(4) ' msoFileDialogFolderPicker
            If .Show Then
                strPath = .SelectedItems(1)
            Else
                MsgBox "You didn't select a folder. Exiting...", vbInformation
                Exit Sub
            End If
        End With
        Application.ScreenUpdating = False
        If Right(strPath, 1) <> "\" Then
            strPath = strPath & "\"
        End If
        strFile = Dir(strPath & "*.doc")
        Do While strFile <> ""
            Set doc = Documents.Open(FileName:=strPath & strFile, _
                AddToRecentFiles:=False)
            doc.SaveAs FileName:=strPath & strFile & "x", _
                FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
            doc.Close SaveChanges:=False
            strFile = Dir
        Loop
        Application.ScreenUpdating = True
    End Sub
    


    Warnings:

    • The code will fail if it encounters a password-protected document.
    • Since .docx cannot store macros, you'll have problems if there are documents that contain macros.

    Do you have a pressing need to convert? Word 2007 can open and save Word 97-2003 documents (.doc) without problems. 


    Regards, Hans Vogelaar
    • Marked as answer by KCDW Tuesday, November 1, 2011 6:57 PM
    Monday, October 31, 2011 9:50 PM
  • Thanks Hans,

    I'll have to try this tommorrow.

    no Macros.


    Chris Ward
    Monday, October 31, 2011 9:58 PM
  • Hi KCDW

    There are any number of tools available. With Office 2007 Microsoft also released a batch migration tool. See

    http://blogs.msdn.com/b/ericwhite/archive/2008/09/19/bulk-convert-doc-to-docx.aspx

    http://www.microsoft.com/download/en/details.aspx?DisplayLang=en&id=21888


    Cindy Meister, VSTO/Word MVP
    Tuesday, November 1, 2011 7:50 AM
    Moderator
  • Thanks Cindy,

    I'll ask to have this installed. We are locked down in this regard and takes a while to get permission to install anything.

    Hans where do I build this Macro? VB6?

    We have users who take old documents and save it with a different name in the old format. After many months it has been determined the best course of action is to change the format they copy from to the format that is desired. Yesterday I manually converted 418 files in about 4 hours. Since there are more than 6,500 files I don't want to manually do the rest and I would like to increase my knowledge.


    Chris Ward
    Tuesday, November 1, 2011 4:57 PM
  • You can create the macro in a Word document or template. For example:

    • Start Word.
    • Press Alt+F11 to activate the Visual Basic Editor.
    • Select Insert | Module to create a new module.
    • Copy/paste the ConvertDoc2Docx macro into the module.
    • Switch back to Word.
    • Save the document as a macro-enabled document (.docm) in a folder that is designated as a trusted location.
    • Whenever you want to convert a bunch of documents in a folder, open this document, then press Alt+F8 to display the Macros dialog. Select ConvertDoc2Docx and click Run.

    Regards, Hans Vogelaar
    • Marked as answer by KCDW Tuesday, November 1, 2011 6:57 PM
    Tuesday, November 1, 2011 5:43 PM
  • Hans,

    This works very well, thank you.

    1) In addition to creating the docx, another file is created for each file doxx. Is this a backup of the original?

    2) Can you specify a new folder location for the converted files? Just put a folder in the current =strpath (converted docx) as

        Do While strFile <> ""
            Set doc = Documents.Open(FileName:=strPath & strFile, _
                AddToRecentFiles:=False)
            doc.SaveAs FileName:=strPath &"\converted docx" & strFile & "x", _
                FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
            doc.Close SaveChanges:=False
            strFile = Dir
        Loop

    3) Can there be a prompt for password so that I can enter the password instead of it failing?


    Chris Ward
    • Marked as answer by KCDW Tuesday, November 1, 2011 6:57 PM
    Tuesday, November 1, 2011 6:16 PM
  • 1) No idea where a .doxx file would come from. Sorry...

    2) That should work.

    3) I'd expect the password prompt to be displayed.


    Regards, Hans Vogelaar
    • Marked as answer by KCDW Tuesday, November 1, 2011 6:57 PM
    Tuesday, November 1, 2011 6:40 PM
  • Oops that actually changed the name of the document to include converted docx at the beginning and did not move it to the desired file I must have the insertion of the code in the wrong place.
    Chris Ward
    Tuesday, November 1, 2011 7:22 PM
  • How about

    doc.SaveAs FileName:=strPath &"converted docx\" & strFile & "x", _
                 FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
     
    


    Regards, Hans Vogelaar
    • Marked as answer by KCDW Tuesday, November 1, 2011 7:43 PM
    Tuesday, November 1, 2011 7:28 PM
  •         doc.SaveAs FileName:=strPath &"Converted docx\" & strFile & "x", _
                FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False

    This gives a runtime error 5152 not a valid file name


    Chris Ward
    Tuesday, November 1, 2011 7:39 PM
  • Okay I see it will save it after the folder is created. Anyway to create the folder at the time of running?
    Chris Ward
    Tuesday, November 1, 2011 7:41 PM
  • To create a subfolder of an existing folder, you can use

    MkDir strPath & "Converted docx"
    

    You should do this after prompting the user for the folder, but before the loop (not inside the loop).


    Regards, Hans Vogelaar
    Tuesday, November 1, 2011 8:25 PM