Solved

macro vba : convert doc to xml

Posted on 2012-12-26
14
427 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
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.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

773 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