Solved

macro vba : convert doc to xml

Posted on 2012-12-26
14
428 Views
Last Modified: 2012-12-27
Hello,

i try to modify this code vba to convert doc to xml but there si an syntax error :
'WdDoc.SaveAs (XML)
 
WdDoc.SaveAs (doc, WdSaveFormat.wdFormatXMLDocument)

WdApp.DisplayAlerts = True

How can I resolve this problem?

Thanks

bibi
0
Comment
Question by:bibi92
  • 7
  • 4
  • 2
  • +1
14 Comments
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38721104
Remove the parenthesis:
WdDoc.SaveAs doc, WdSaveFormat.wdFormatXMLDocument
0
 

Author Comment

by:bibi92
ID: 38721207
Hello,

Thanks but it doesn't work :
WdDoc.SaveAs Doc, WdSaveFormat.wdFormatXMLDocument ---> error 424 object required.

Bibi
0
 
LVL 40
ID: 38721575
What do you have in the Doc variable?
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

Author Comment

by:bibi92
ID: 38721607
Dim WdDoc As Object
Thanks bibi
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38721638
Your code should look something like this:
Dim wdDoc As Object
Dim doc As String

Set wdDoc = ActiveDocument
doc = "NameOfFile.xml"
wdDoc.SaveAs doc, WdSaveFormat.wdFormatXMLDocument

Open in new window

0
 

Author Comment

by:bibi92
ID: 38721655
It doesn't work.
I generate a word doc like :
Set WdApp = CreateObject("Word.Application")
WdApp.Application.Visible = False

Set WdDoc = WdApp.Documents.Open(ModName)
Thanks
0
 
LVL 40
ID: 38721868
"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?
0
 

Author Comment

by:bibi92
ID: 38722182
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.

Thanks

bibi
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 38722203
Does it work if you change to

WdDoc.SaveAs Doc, 12
0
 
LVL 40
ID: 38722229
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.
0
 

Author Comment

by:bibi92
ID: 38723456
I have tried WdDoc.SaveAs Doc, 12. It doesn't work. Regards bibi
0
 

Author Closing Comment

by:bibi92
ID: 38723466
Hello,

Thanks for your help, I have modified the macro like this :
Doc = RepR & serveur & " - " & NomFile & ".xml"


wdDoc.SaveAs Doc, 7

It works.

Regards

Bibi
0
 
LVL 40
ID: 38724315
Why do you accept a solution that you say does not work, while I pointed out twice that we needed to see what was in Doc?

Saving with a format of 7 is equivalent of wdFormatEncodedText, which as nothing to do with what you were searching to do from the start.
0
 

Author Comment

by:bibi92
ID: 38724501
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
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question