Solved

macro vba : convert doc to xml

Posted on 2012-12-26
14
425 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now