?
Solved

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

Posted on 2010-11-24
6
Medium Priority
?
1,479 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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Technology Partners: 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!

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

840 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