Run a batch file within batch file using VBA (1 Viewer)

wasim_sono

Registered User.
Local time
Today, 17:39
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.
 

Ranman256

Well-known member
Local time
Today, 09:39
Joined
Apr 9, 2015
Messages
4,339
can you not just run both bat in vba?

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

wasim_sono

Registered User.
Local time
Today, 17:39
Joined
May 29, 2008
Messages
33
Thanks Ranman256

I did it but same result. rc files converted into text file only. No dataFile is created.
 

JHB

Have been here a while
Local time
Today, 15:39
Joined
Jun 17, 2012
Messages
7,732
..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.
 

JHB

Have been here a while
Local time
Today, 15:39
Joined
Jun 17, 2012
Messages
7,732
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"
 

Cronk

Registered User.
Local time
Today, 23:39
Joined
Jul 4, 2013
Messages
2,771
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
 

wasim_sono

Registered User.
Local time
Today, 17:39
Joined
May 29, 2008
Messages
33
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.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 21:39
Joined
May 7, 2009
Messages
19,231
in plain language, what does the two .bat files do?
 

Cronk

Registered User.
Local time
Today, 23:39
Joined
Jul 4, 2013
Messages
2,771
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

Top Bottom