Search code examples
excelvbams-worddocxdoc

VBA: Word saves .docx file as a .doc file, how to save as a docx?


In Excel I have a few macro's that work perfect. What I do with these macro's is open a Word document (.docx), fill the bookmarks with data from the Excel file, save the separate Word documents with some data in the filename, in a specified folder. No big deal (anymore).

The thing is that the input files are .docx files. The output files are .doc (Word 97-2003 compatible).

How to save the output documents as .docx files? The part of my VBA that is responsible for the saving is this:

wordApp.DisplayAlerts = False
    WordDoc.SaveAs Filename:=ThisWorkbook.Path & "GoNoGo\GoNoGo BOL " & strVoornaam & Space(1) & strAchternaam, FileFormat:=wdFormatDocument
    WordDoc.Close
    wordApp.Quit
    Set WordDoc = Nothing
    Set wordApp = Nothing

Solution

  • With this:

    FileFormat:=wdFormatDocument
    

    You are telling VBA to save as .doc.

    It should be:

    FileFormat:=wdFormatDocumentDefault
    

    Check out the possible files formats here:

    https://msdn.microsoft.com/de-de/vba/word-vba/articles/wdsaveformat-enumeration-word