Solved

Running a DOS Batch File, running a Word macro, trying to run a DOS batch file

Posted on 2010-11-24
6
1,365 Views
Last Modified: 2013-11-05
I am using a DOS batch file to run a Word macro i.e. in the batch file - mybatch.bat is the command line:

winword /mMyMacro /t DocumentName.docm

Where DocumentName.docm is my Word document containing the macro and MyMacro is the macro that initiates the process I want to run.

Contained within the process is a subroutine that creates a batch file to process a FTP statement to upload documents to a website. The batch file is executed within the macro using the code:

dRetVal = Shell(Batch_Filename, 0)

Where Batch_Filename is the batch file created by the macro.

This works if the MyMacro macro is initiated by opening up the DocumentName.docm and running the MyMacro macro, but does work if initiated from a batch file, i.e. it will not allow a batch file to be run from within a batch file.

Does anyone have a workaround for this? If I was doing it manually I would "call" the second batch file.
0
Comment
Question by:DavidAreen
[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
  • 4
  • 2
6 Comments
 
LVL 11

Expert Comment

by:dougaug
ID: 34209340
When you call your macro from batch file, any others commands inside your macro are executed or just the line dRetVal = Shell(Batch_Filename, 0)?

If none commands are executed, you should enable Word option to allow execution of macros without being notified.

What Word version are you using?
0
 
LVL 1

Author Comment

by:DavidAreen
ID: 34209440
Hi dougaug

It processes a whole load of input files and macros - creates a whole load of files in loads of different formats, i.e. generates XML files, BMP images, Word and PowerPoint files.

The dRetVal = Shell(Batch_Filename, 0) line is simply one subroutine in the process.

I'm not sure that it really matters if I set Application.ScreenUpdating = False or not. As it is it doesn't suppress all the output but I'm not concerned about that.

The FTP batchfile is not executed unless I run the macro outside the DOS .bat file.

I'm using Word 2010




0
 
LVL 11

Expert Comment

by:dougaug
ID: 34213781
OK, DavidAreen, but I've asked you if when call your Macro from DOS batch file, all other commands inside your Macro are executed except Shell(Batch_Filename, 0).

As you've explained, Batch_Filename is created by your Macro. Have you checked if this file is really created when you call your Macro from DOS?

Could you post your Macro and DOS batch file here, please?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:DavidAreen
ID: 34214075
Hi Dougaug

I can confirm that all the other procedures work, the bat file is created. I can't paste the code here because it is too long and the bat file contains confidential information.

I can confirm that if I open the DocumentName.docm and run the MyMacro the DOS bat file that is created by the procedure is correctly executed.

I can also process the bat files manually.

I am totally confident that the problem is trying to run a bat file within a bat file. I was hoping that someone might be able to advise how I could use the Shell to 'Call' the second bat file; or perhaps create a new DOS 'run' stream to run the second bat file independently from the first.

If that is not possible I will probably look to code VBA FTP calls, or change the controlling bat file so that it processes the procedure's created bat files once the procedure has completed.

Hope that clarifies things a bit better.  
0
 
LVL 1

Accepted Solution

by:
DavidAreen earned 0 total points
ID: 34217571
Okay problem solved.

I went back to basics and isolated all the relevant code and ran some tests. The batch file was being run but when run from another batch file it was not recognizing the FTP command. I inserted a  "SET PATH=\Windows\system32;" line before the FTP statement and it worked.

Not sure exactly why the batch file should work when run from within the document and not from outside but I'm sure there is a logical reason.

Thanks Dougang for your input.
0
 
LVL 1

Author Closing Comment

by:DavidAreen
ID: 34246271
Problem solved.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

726 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