Solved

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

Posted on 2010-11-24
6
1,310 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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

12 Experts available now in Live!

Get 1:1 Help Now