Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

macro vba : convert doc to xml

Posted on 2012-12-26
14
Medium Priority
?
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 1500 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

636 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