Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

Saving Word doc as XML from VBScript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason Reichenbach - 18 Feb 2005 15:53 GMT
I am new to VBScript, and automating Word, so I'm probably doing something
dumb.

I have a series of Word documents that I need to save in XML format. There
are hundreds, so I need to do it automatically. I have the following VBScript
(clearly doesn't handle the hundreds issue, but it won't work on one file
yet):

'==========================
' Script starts
dim inFile
dim outfile

' Define intput and output file paths
inFile = "D:\My Documents\TestData\Test.doc"
outfile = "D:\My Documents\TestData\Test.xml"

' Start Microsoft Word...
dim w
set w = createobject("word.application")

' Visibility will ultimately be false
w.visible = true

' Open a document as read only
dim d
set d = w.documents.open (inFile, False, True)

' Save it as XML
d.SaveAs outfile, wdFormatXML

w.Quit

' Script ends
'===================

The output file gets saved to the correct name, but not in XML format. What
I end up with is a Word document with an .xml extension. If I rename the file
to have a .doc extension it opens in word.

When I do the same thing manually by opening the file then selecting File |
SaveAs and selecting the XML Document type option, it works as expected and I
get an actual XML output file.

What am I doing wrong, here?
Many thanks in advance.
Jason Reichenbach - 18 Feb 2005 17:29 GMT
OK, it is a dumb mistake... The symbol   wdFormatXML has no meaning in the
context where it is being used: the vb script. It only has meaning inside the
Word application object.

So now the question is, can I access this constant by name from outside the
word application, so I can pass its value in the script. Its value happens to
be 11, but I'd rather access it by name from Word if possible.

Any ideas on this?

> I am new to VBScript, and automating Word, so I'm probably doing something
> dumb.
[quoted text clipped - 42 lines]
> What am I doing wrong, here?
> Many thanks in advance.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.