Solved

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

Posted on 2010-11-24
6
1,341 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel VBA 4 29
macro modification Column C 14 32
Why do my Excel files become huge? 27 36
formatting - number format 2 15
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,…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

825 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