Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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,443 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
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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 Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

618 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