Page 1 of 1

Run a batch file within batch file using VBA

Posted: 01 Feb 2018 22:09
by wasimsono
Dear all

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

The contents of Combine.bat file are as:

Code: Select all

@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: Select all

@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: Select all

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.

Re: Run a batch file within batch file using VBA

Posted: 01 Feb 2018 22:41
by ShadowThief
The line in Picenquiry.bat that calls combine.bat is commented out.

Re: Run a batch file within batch file using VBA

Posted: 02 Feb 2018 01:18
by wasimsono
If I remove Comment then also same result found. How can I run second batch file within Picenquiry.bat ?

Re: Run a batch file within batch file using VBA

Posted: 13 Feb 2018 04:25
by wasimsono
I removed comment.
I also run only combine.bat file but still no result found.

Anyone can help out.

regards.

Re: Run a batch file within batch file using VBA

Posted: 13 Feb 2018 06:16
by penpen
The Phrases "If I remove Comment" and "I removed comment." sound like you have misunderstood ShadowThief.
I'm pretty sure he wanted you to end up with this "Picenquiry.bat" (which successfully processed the related "combine.bat"):

Code: Select all

@echo off
ren "F:\meter_pictures\??????rc*." *.txt 
call "F:\meter_pictures\combine.bat"
penpen

Re: Run a batch file within batch file using VBA

Posted: 13 Feb 2018 13:10
by ShadowThief
Yes, all I wanted was the "rem" to be removed, not the entire line.

Re: Run a batch file within batch file using VBA

Posted: 13 Feb 2018 22:03
by wasimsono
Thanks for your reply.

Now I used following code:

Code: Select all

@echo off
ren "F:\meter_pictures\??????rc*." *.txt 
call "F:\meter_pictures\combine.bat"
but only first line executed i.e.

Code: Select all

@echo off
ren "F:\meter_pictures\??????rc*." *.txt 

Re: Run a batch file within batch file using VBA

Posted: 14 Feb 2018 03:14
by ShadowThief
Is the rename actually working correctly?

Re: Run a batch file within batch file using VBA

Posted: 14 Feb 2018 03:58
by wasimsono
yes, rename working correctly.

Re: Run a batch file within batch file using VBA

Posted: 14 Feb 2018 04:12
by ShadowThief
https://stackoverflow.com/questions/944 ... g-properly suggests that VBA calls batch scripts from a certain directory. Try sticking a

Code: Select all

pushd %0
after the first line in combine.bat