Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-03-2016, 07:09 AM
michele82 michele82 is offline Macro word 2010 to save word file into xml Windows Vista Macro word 2010 to save word file into xml Office 2010 32bit
Novice
Macro word 2010 to save word file into xml
 
Join Date: Feb 2016
Posts: 3
michele82 is on a distinguished road
Default Macro word 2010 to save word file into xml

Hi,
i want to create a macro in word 2010 to save all .doc and .docx files in a folder,
to another folder in .xml format.


Someone can give me some suggestion on how to do?
Reply With Quote
  #2  
Old 02-04-2016, 06:38 AM
gmayor's Avatar
gmayor gmayor is offline Macro word 2010 to save word file into xml Windows 10 Macro word 2010 to save word file into xml Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following should do the job. The modified documents will be saved in the named folder at strNewPath (which miust exist).
Code:
Sub SaveAsXML()
Dim fDialog As FileDialog
Dim oDoc As Document
Dim strPath As String
Dim strFile As String
Const strNewPath As String = "C:\Path\"
Dim strName As String
    On Error GoTo err_Handler
    Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
    With fDialog
        .Title = "Select folder and click OK"
        .AllowMultiSelect = False
        .InitialView = msoFileDialogViewList
        If .Show <> -1 Then
            MsgBox "Cancelled By User", , "List Folder Contents"
            GoTo lbl_Exit
        End If
        strPath = fDialog.SelectedItems.Item(1)
        If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
    End With
    If Documents.Count > 0 Then
        Documents.Close SaveChanges:=wdPromptToSaveChanges
    End If
    strFile = Dir$(strPath & "*.doc")
    While strFile <> ""
        Set oDoc = Documents.Open(strPath & strFile)
        strName = Left(oDoc.name, Len(oDoc.name) - InStrRev(oDoc.name, Chr(46))) & ".xml"
        oDoc.SaveAs2 Filename:=strNewPath & strName, FileFormat:=wdFormatXML, AddToRecentFiles:=False
        oDoc.Close 0
        strFile = Dir$()
    Wend
lbl_Exit:
    Exit Sub
err_Handler:
    Err.Clear
    GoTo lbl_Exit
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 02-05-2016, 07:01 AM
michele82 michele82 is offline Macro word 2010 to save word file into xml Windows Vista Macro word 2010 to save word file into xml Office 2010 32bit
Novice
Macro word 2010 to save word file into xml
 
Join Date: Feb 2016
Posts: 3
michele82 is on a distinguished road
Default

Thanks gmayor,
your code does just what i wanted to do, the only thing is that it saves all documents in the folder selected except the last one, why do you think?
Reply With Quote
  #4  
Old 02-17-2016, 03:44 AM
michele82 michele82 is offline Macro word 2010 to save word file into xml Windows Vista Macro word 2010 to save word file into xml Office 2010 32bit
Novice
Macro word 2010 to save word file into xml
 
Join Date: Feb 2016
Posts: 3
michele82 is on a distinguished road
Default

If i want to do the same also for the .docx? It's possible?
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I save a Word file with a macro for distribution? leemoreau Word VBA 3 10-04-2013 08:06 AM
Macro word 2010 to save word file into xml Macro to create new word doc and save the file using String found in the document VBNation Word VBA 2 02-08-2013 07:14 AM
Unable to File>Save As.. or Open in Word 2010, please help BrokenComputer Word 0 03-07-2012 10:20 PM
Macro word 2010 to save word file into xml A newbie question: a must to save macro word file as .docm? tinfanide Word VBA 6 12-06-2011 03:02 PM
Macro word 2010 to save word file into xml Word Macro: Save file as text with current file name jabberwocky12 Word VBA 2 10-22-2010 12:23 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:21 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft