#1
|
|||
|
|||
Run macro to save multiple word docs and xml
Hello all,
I am trying to write a macro to convert all the word docs in a specific folder into flat XML . I have been able to come up with the below code, but it's not working. can anyone please let me know how to resolve it. Code:
Sub BatchConvertDocToXML() Dim objDoc As Document Dim strFile As String, strFolder As String 'Initialization strFolder = "D:\XXXX\Original\" strFile = Dir(strFolder & "*.doc", vbNormal) 'Process each file in the file folder and convert them to xml. While strFile <> "" Set wdDoc = Documents.Open(FileName:=strFolder & strFile, AddToRecentFiles:=False, Visible:=False) 'insert code here wdDoc.SaveAs2 FileName:=strFile, FileFormat:=wdFormatFlatXML, LockComments:=False, Password:="", _ AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _ EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _ :=False, SaveAsAOCELetter:=False, CompatibilityMode:=15 wdDoc.Close strFile = Dir() Wend End Sub Last edited by macropod; 02-05-2018 at 02:47 PM. Reason: Added code tags |
#2
|
||||
|
||||
Try:
Code:
Sub BatchConvertDocToXML() Dim wdDoc As Document Dim strFile As String, strFolder As String 'Initialization strFolder = "D:\XXXX\Original\" strFile = Dir(strFolder & "*.doc", vbNormal) 'Process each file in the file folder and convert them to xml. While strFile <> "" Set wdDoc = Documents.Open(FileName:=strFolder & strFile, ReadOnly:=True, AddToRecentFiles:=False, Visible:=False) wdDoc.SaveAs2 FileName:=strFolder & Split(strFile, ".doc")(0) & ".xml", FileFormat:=wdFormatFlatXML, AddToRecentFiles:=False wdDoc.Close False strFile = Dir() Wend End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
macro |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Having Issues Applying a Macro Across Multiple Files. Changes Just Don't Seem To Save. | Kajex | Word VBA | 2 | 09-08-2017 06:37 AM |
Word always brings up 'Save As' dialogue when I try to Save - same for all Word docs | stuartb | Word | 1 | 08-18-2014 12:26 PM |
Add watermark to multiple word docs | mykeee | Word | 1 | 09-21-2013 04:01 PM |
Sequential Page Numbering of Multiple Word Docs | bobmard | Word | 8 | 08-24-2011 08:51 AM |
Amend footer in multiple word docs? | compact | Word | 2 | 02-24-2009 09:40 AM |