#1
|
|||
|
|||
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? |
#2
|
||||
|
||||
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 |
#3
|
|||
|
|||
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? |
#4
|
|||
|
|||
If i want to do the same also for the .docx? It's possible?
|
|
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 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 |
A newbie question: a must to save macro word file as .docm? | tinfanide | Word VBA | 6 | 12-06-2011 03:02 PM |
Word Macro: Save file as text with current file name | jabberwocky12 | Word VBA | 2 | 10-22-2010 12:23 PM |