Solved

.bat file to open multiple word documents and run macro

Posted on 2013-11-07
9
2,844 Views
Last Modified: 2013-11-17
Hello,

I have created a MS Word macro that converts an XML document open in Word to a .doc format.

I have a set of XML documents that I would like to open and convert to MS Word, they are all named differently but still have the same XML file extension.  

I have this line of code that I put in a .bat file to open a XML file and run the macro, this works fine.

"C:\Program Files (x86)\Microsoft Office\Office14\winword" C:\Users\wlotzkan\Desktop\CC\*.xml /mSaveAsDoc

Open in new window


Now how can I get the .bat file to open and convert every XML file in the folder to a .doc file?  Here is what I have so far....but I cant get it to work.
FORFILES /M *.xml /C "C:\Program Files (x86)\Microsoft Office\Office14\winword" /mSaveAsDoc

Open in new window


Thanks!
0
Comment
Question by:navid86
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
9 Comments
 
LVL 26

Expert Comment

by:pony10us
ID: 39630686
Try moving the closing quote to the end (after the WinWord macro)

FORFILES /m *.xml /C "C:\Program Files (x86)\Microsoft Office\Office14\winword /mSaveAsDoc"

Open in new window

0
 
LVL 2

Author Comment

by:navid86
ID: 39630924
Okay, I tried that, the CMD window comes up and it looks like it is executing it for every file, but then it doesnt do anything.  Doesnt open any of the documents.
0
 
LVL 2

Author Comment

by:navid86
ID: 39631110
I ran the bat file in the command prompt window and it seems like it cannot find the files in the folder at all.

ERROR: The system cannot find the file specified
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 26

Expert Comment

by:pony10us
ID: 39631179
Are you running this from within the folder the files are located?  If not then you may need to add the path:

FORFILES /p  <path> /m *.xml /C "C:\Program Files (x86)\Microsoft Office\Office14\winword /mSaveAsDoc"

Open in new window

0
 
LVL 2

Author Comment

by:navid86
ID: 39631592
Yes, I am running it from within the same folder, so the path isn't an issue.  I am starting to think that the FORFILES command is probably not the right thing to use in this case.  I removed all XML files from the folder, except for 2 of them and in command prompt when i execute the line of code above it shows like 50 of the same error message.

ERROR: The system cannot find the file specified.

Any other suggestions?
0
 
LVL 38

Accepted Solution

by:
BillDL earned 500 total points
ID: 39634042
Try this:

Directly from the command line after changing directory to the root of the folder containing the *.xml files:

for /r %A in (*.xml) do call "C:\Program Files (x86)\Microsoft Office\Office14\winword.exe" "%A" /mSaveAsDoc

As a batch file run from the root of the folder containing the *.xml files:

@echo off
for /r %%A in (*.xml) do call "C:\Program Files (x86)\Microsoft Office\Office14\winword.exe" "%%A" /mSaveAsDoc
pause
0
 
LVL 2

Assisted Solution

by:navid86
navid86 earned 0 total points
ID: 39641748
Thanks BillDL!  Worked perfectly.  All i did is add a /q to the code to hide the MS Word splash screen.

Thanks a lot for your help!

@echo off
for /r %%A in (*.xml) do call "C:\Program Files (x86)\Microsoft Office\Office14\winword.exe" /q "%%A" /mSaveAsDoc
pause

Open in new window

0
 
LVL 2

Author Closing Comment

by:navid86
ID: 39654302
The final solution for me was adding a /q to to the code.  However BillDL helped fix the majority issues.
0
 
LVL 38

Expert Comment

by:BillDL
ID: 39654610
Thank you Navid.  Glad it worked.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
The viewer will learn how to dynamically set the form action using jQuery.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question