Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-04-2018, 11:25 PM
Prateep Nath Prateep Nath is offline Run macro to save multiple word docs and xml Windows XP Run macro to save multiple word docs and xml Office 2016
Novice
Run macro to save multiple word docs and xml
 
Join Date: Feb 2018
Posts: 1
Prateep Nath is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 02-05-2018, 02:52 PM
macropod's Avatar
macropod macropod is offline Run macro to save multiple word docs and xml Windows 7 64bit Run macro to save multiple word docs and xml Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
PS: When posting code, please use the code tags, indicated by the # button on the posting menu. Without them, your code loses much of whatever structure it had.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
macro

Thread Tools
Display Modes


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
Run macro to save multiple word docs and xml 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
Run macro to save multiple word docs and xml 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

Other Forums: Access Forums

All times are GMT -7. The time now is 04:58 PM.


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