Solved

macro vba : convert doc to xml

Posted on 2012-12-26
14
422 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
Comment Utility
Remove the parenthesis:
WdDoc.SaveAs doc, WdSaveFormat.wdFormatXMLDocument
0
 

Author Comment

by:bibi92
Comment Utility
Hello,

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

Bibi
0
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
What do you have in the Doc variable?
0
 

Author Comment

by:bibi92
Comment Utility
Dim WdDoc As Object
Thanks bibi
0
 
LVL 29

Expert Comment

by:IrogSinta
Comment Utility
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
Comment Utility
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

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
"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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:bibi92
Comment Utility
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
Comment Utility
Does it work if you change to

WdDoc.SaveAs Doc, 12
0
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
Comment Utility
I have tried WdDoc.SaveAs Doc, 12. It doesn't work. Regards bibi
0
 

Author Closing Comment

by:bibi92
Comment Utility
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

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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;…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

743 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

15 Experts available now in Live!

Get 1:1 Help Now