View Single Post
 
Old 02-04-2016, 06:38 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
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 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