Solved

.bat file to open multiple word documents and run macro

Posted on 2013-11-07
9
2,490 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
  • 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now