Run a batch file within batch file using VBA

wasim_sono

Registered User.
Local time
Today, 11:23
Joined
May 29, 2008
Messages
33
Dear all

I have two batch files named as :
1) Combine.bat
2) Picenquiry.bat

The contents of Combine.bat file are as:
Code:
@echo off
for %%A in (*.txt) do (
  echo Processing file '%%A'
   
  FOR /F "delims=" %%L in (%%A) do (
    ECHO %%L%%A >> DataFile.txt
  )
)
and contents of Picenquiry.bat are as:
Code:
@echo off
ren "F:\meter_pictures\??????rc*." *.txt 
rem call "F:\meter_pictures\combine.bat"

I am using a button on form and following code is used for click on button:
Code:
strReportpath = "F:\meter_pictures\"
Shell strReportpath & "Picenquiry.bat"

Unfortunately It runs but only run Picenquiry.bat file and do not run Combine.bat file as it is called in this batch file.

But when I run Picenquiry.bat file directly without using VBA i.e. by double clicking file name, it runs and make "DataFile.txt".

What mistake I am doing? Please help me. Its urgent.
 
can you not just run both bat in vba?

Shell "F:\meter_pictures\Picenquiry.bat"
shell "F:\meter_pictures\combine.bat"
 
Thanks Ranman256

I did it but same result. rc files converted into text file only. No dataFile is created.
 
..and contents of Picenquiry.bat are as:
Code:
@echo off
ren "F:\meter_pictures\??????rc*." *.txt 
[B][COLOR=Red]rem[/COLOR][/B] call "F:\meter_pictures\combine.bat"
You've a Rem in your code. Rem is used when inserting a comments in the code, so it isn't executed.
 
If I remove rem then also same result found.
Okay, but Rem should definitely not be there.
And the . in this line either.
Code:
ren "F:\meter_pictures\??????rc*[B][COLOR=red].[/COLOR][/B]" *.txt
Try to run it from a DOS promt, (REM the @echo off line.)
So Picenquiry.bat is:
Code:
REM @echo off 
ren "F:\meter_pictures\??????rc*" *.txt  
call "F:\meter_pictures\combine.bat"
 
The original code posted in #1 was

ren "F:\meter_pictures\??????rc*." *.txt
That is trying to give directories file names

Try
ren "F:\meter_pictures\??????rc*.*" *.txt
 
Dear Cronk

Actual problem is that the second line
Code:
call "F:\meter_pictures\combine.bat"
is not executing. But it works fine if we run this batch file directly.
 
in plain language, what does the two .bat files do?
 
From the batch code, it looks like the second batch (Combine.bat) concatenates the text in all text files in the folder to a single file Daily.txt

The first batch file only seems to call the second.

Could use the FileSystemObject as an alternative.
 

Users who are viewing this thread

Back
Top Bottom