dcsimg
Results 1 to 4 of 4

Thread: Save an open word document to an xml file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    305

    Save an open word document to an xml file

    This to me seems simple, but I cannot find it anywhere.

    I want to save an open docx file to an xml file. Is this possible?

    Thanks!

  2. #2
    Frenzied Member jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,427

    Re: Save an open word document to an xml file


  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,444

    Re: Save an open word document to an xml file

    Code:
    ActiveWorkbook.XmlMaps.Add("Book2.xml", "raport").Name _
            = "raport_Map"
    And to save it as xml:

    Code:
    ActiveWorkbook.SaveAsXMLData Filename:="Book3.xml", _
            Map:=ActiveWorkbook.XmlMaps("raport_Map")
    from https://stackoverflow.com/questions/...s-xml-with-vba
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Posts
    305

    Re: Save an open word document to an xml file

    Something like this (though not this) in Word?

    Code:
            ' Open Document
            Dim oWord As Microsoft.Office.Interop.Word.Application
            Dim oDoc As Microsoft.Office.Interop.Word.Document
            oWord = CreateObject("Word.Application")
            oWord.Visible = True
            oDoc = oWord.Documents.Open(FullFilePath)
    
            Dim OutputFile As String = "C:\Temp\" & System.IO.Path.GetFileNameWithoutExtension(oDoc.Name) & ".xml"
            Debug.WriteLine(OutputFile)
    
            oDoc.XMLSaveDataOnly(OutputFile)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width