"I generate a word doc like". The "like" is never a good thing when you as a question. Very often, programmers who give us code that is "like" the original do not include the part that gives the problem.
Can you post the "real" code?
bibi92
ASKER
In vba excel macro :
Dim wdDoc As Object
Set WdApp = CreateObject("Word.Application")
WdApp.Application.Visible = False
Set WdDoc = WdApp.Documents.Open(ModName)
WdDoc.SaveAs Doc, WdSaveFormat.wdFormatXMLDocument ---> error 424 object required.
This is incomplete. We do not have the declaration for WdApp, and we do not have the declaration and assignment to variables ModName and Doc. All of these come into play. Since once again we have only part of the code, the lines that code the problem might be missing.
Also, the type of code you are using is 20 years old... although you still find that on the Internet all the time. If you want to help yourself and help the VBA editor in helping you, try not to use Object variables.
It probably won't solve your problem, but it will make coding a lot easier because the compiler will be able to detect problems before you run the macro.
First, from the VBA window, reference Microsoft Word in Tools...References. This way, you will be able to use the Word constants instead of having to simply use 12 as Code Cruiser suggested.
Then, declare your objects this way:
Dim WdApp as Word.Application
Dim wdDoc As Word.Document
Set WdApp = New Word.Application
Object can be anything. By declaring as I do, because the compiler knows what WdApp and WdDoc are, it can check a lot of things that it cannot check when you declare a variable as Object. And you will gain IntelliSense, those little lists of properties and methods that appear to offer what is available when you type.
yes I Know That but the post of codecruiser help me to find the solution. I can not modify all code because it s for helping a collègue. The goal was to generate file for loading in Controlm and it works with
Wddoc.saveas doc, 7
Thanks a lot
WdDoc.SaveAs doc, WdSaveFormat.wdFormatXMLDo