Here is batch file code:
@echo off >summary.txt (
for %%F in (*chkpackage.log) do findstr /l %1 "%%F" nul||echo %% F:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A:N/A)
and here is the code in VBA Excel calling the batch file:
FileSet = Sheet1.Range("C13")
txtFpath = Sheet1.Range("C7").Value
FilePath = txtFpath & "\res.bat"
ChDrive "D"
RSP = Shell(Environ$("COMSPEC"), vbNormalFocus)
Application.Wait Now + TimeValue("00:00:03")
SendKeys "CD " & txtFpath & "{ENTER}", True
Application.Wait Now + TimeValue("00:00:03")
SendKeys "start " & FilePath & " " & FileSet & "{ENTER}", True
Application.Wait Now + TimeValue("00:00:03")
SendKeys "exit " & "{ENTER}", True
Application.Wait Now + TimeValue("00:00:03")
SendKeys "exit " & "{ENTER}", True
But I don’t want to use a batch file. I want to change it into command to use on VBA.
So i can use only VBA and run command line instead of using VBA to call batch and command line.
Easy explanation is I want to put that command in batch file into Excel-VBA and run it by using VBA call cmd and auto input that command to cmd like that Sendkeys code.
You can add a reference to the
Microsoft Scripting Runtime(Tools -> References from the VBA IDE), which provides the FileSystemObject and allows you to do the following:You can limit the files to a particular pattern using the Like operator:
You can use the OpenAsTextStream method to get a TextStream object, and the ReadAll method to read the file contents:
You can use
Split(contents, vbCrLf)to split the contents into an array of lines before parsing (usevbLforvbCrif the line delimiter is Unix/Mac and not Windows).Alternatively, you can use the
ReadLinemethod to read the file line by line. You need to check theAtEndOfStreamproperty to ensure that you’re not trying to read past the end of the file: