Save word doc to XML

I’m trying to save a word doc that I’ve created via the com object to xml. I’ve created a macro in word and converted it to lotus script but for some reason I can get it to accept my xls style sheet that I got from microsoft to convert it to a fo file. Which I will then convert to a pdf. Any way here’s the code. Maybe a fresh pair of eyes will help. All I want to do is save the file as an xml file using the xls stylesheet.It works in word but not via this script.

Set wordapp = createObject( “word.Application” )

Call wordapp.documents.add("c:\template.dot") 'Create a new document based on the template "Task.Dot"	

wordapp.Visible = False





wordapp.ActiveDocument.FormFields("Text1").Result = doc.CustAddress(0)

wordapp.ActiveDocument.FormFields("Text2").Result = doc.CustAddress(1)

wordapp.ActiveDocument.FormFields("Text3").Result = doc.CustAddress(2)

wordapp.ActiveDocument.FormFields("Text4").Result = doc.ProjectNumber(0)

wordapp.ActiveDocument.FormFields("Text5").Result = doc.TransmittalNumber(0)

wordapp.ActiveDocument.XMLSaveDataOnly = True

wordapp.ActiveDocument.XMLUseXSLTWhenSaving = True

wordapp.ActiveDocument.XMLSaveThroughXSLT ="C:\Office Samples\OfficeWordWordMLtoXSL-FO\Word2FO.xsl"

wordapp.ActiveDocument.XMLHideNamespaces = False

wordapp.ActiveDocument.XMLShowAdvancedErrors = False

wordapp.ActiveDocument.XMLSchemaReferences.HideValidationErrors = False

wordapp.ActiveDocument.XMLSchemaReferences.AutomaticValidation = True

wordapp.ActiveDocument.XMLSchemaReferences.IgnoreMixedContent = True

wordapp.ActiveDocument.XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = True

wordapp.ActiveDocument.XMLSchemaReferences.ShowPlaceholderText = False	



savestringxml = "c:\" + doc.TransmittalNumber(0) + ".xml"

'parms for saveas word document

wordapp.ActiveDocument.SaveAs "c:\test.xml",wdFormatXML

	wordapp.ActiveDocument.Close

Call wordApp.Quit 

Set wordapp = Nothing

Subject: Save word doc to XML

LotusScript doesn’t know what the “wdWhateverThingy” constants are. You’ll need to get the value of wdFormatXML and use that (from the VBA debugger or the Immediate window – it’ll be a number).

Subject: RE: Save word doc to XML

If it’s any help, I usually use the VBA Object Browser to get method parameters and constant values.

Subject: RE: Save word doc to XML

Okay I figured it out thanks for the help.Your right lotus script doesn’t know about the com parameters but I had to do some heavy diggin on the microsoft site to come up with the correct parameters. Note that you need to provide the wdformatXML Constant of 11 for XML and 8 for Html

I’ve posted the correct code for the solution.

The first two lines are all you need to get it to work.

Const wdFormatXML = 11 ’ for saving to XML

Const wdFormat HTML = 8 ’ for saving to HTML

Set wordapp = createObject( “word.Application” )

Call wordapp.documents.add(“c:\template.dot”) 'Create a new document based on the template “Task.Dot”

wordapp.Visible = False

wordapp.ActiveDocument.FormFields(“Text1”).Result = doc.CustAddress(0)

wordapp.ActiveDocument.FormFields(“Text2”).Result = doc.CustAddress(1)

wordapp.ActiveDocument.FormFields(“Text3”).Result = doc.CustAddress(2)

wordapp.ActiveDocument.FormFields(“Text4”).Result = doc.ProjectNumber(0)

wordapp.ActiveDocument.FormFields(“Text5”).Result = doc.TransmittalNumber(0)

wordapp.ActiveDocument.XMLSaveDataOnly = True

wordapp.ActiveDocument.XMLUseXSLTWhenSaving = True

wordapp.ActiveDocument.XMLSaveThroughXSLT =“C:\Office Samples\OfficeWordWordMLtoXSL-FO\Word2FO.xsl”

wordapp.ActiveDocument.XMLHideNamespaces = False

wordapp.ActiveDocument.XMLShowAdvancedErrors = False

wordapp.ActiveDocument.XMLSchemaReferences.HideValidationErrors = False

wordapp.ActiveDocument.XMLSchemaReferences.AutomaticValidation = True

wordapp.ActiveDocument.XMLSchemaReferences.IgnoreMixedContent = True

wordapp.ActiveDocument.XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = True

wordapp.ActiveDocument.XMLSchemaReferences.ShowPlaceholderText = False

savestringxml = "c:" + doc.TransmittalNumber(0) + “.xml”

'parms for saveas word document

wordapp.ActiveDocument.SaveAs “c:\test.xml”,wdFormatXML

wordapp.ActiveDocument.Close

Call wordApp.Quit

Set wordapp = Nothing