J
Jason Reichenbach
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.
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.