Solved

.bat file to open multiple word documents and run macro

Posted on 2013-11-07
9
2,768 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
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

751 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