Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

.bat file to open multiple word documents and run macro

Posted on 2013-11-07
9
Medium Priority
?
3,018 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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 39

Accepted Solution

by:
BillDL earned 2000 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 39

Expert Comment

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

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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 video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

885 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