1
votes

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
1
msdn.microsoft.com/en-us/vba/word-vba/articles/… Are you using late binding? If Yes you need to define the file format constant - Tim Williams
Crap, I missed that. Thanks a lot. It's solved now. I have no clue about late binding or not. It's my first VBA project, with a lot of help from people on the internet. - Sypie
If you're referencing the Word object model / type library, Word constants are defined and you should declare Word objects using the types defined in the Word object model. If you're not referencing the Word type library, Word constants are NOT defined and you should use their underlying value, and you need to late-bind the object types, i.e. declare them As Object, which makes VBA resolve the actual types at run-time (hence, late binding, vs compile-time / early binding). - Mathieu Guindon

1 Answers

1
votes

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