I am working on a project for work, where i need to create a batch file, run the file, then delete it.
The batch file looks for text files with a set name in the current folder and subfolders and combines them into one text file.
The batch file is running correctly, but it is running from 1 directory up.
For example, the excel file with the VBA code is here:
G:\Dropbox\DT\WORK\Phases - 101-102-103-104-105-106-107-108-109
But the batch file is being created here:
Public Sub MCS_to_Accessories() 'STAGE 1 'Creates a batch file to combine all the AccReport.txt files together to create one Master text file, then deletes itself. Const MY_FILENAME = "AccReportMerge.BAT" Dim FileNumber As Integer Dim retVal As Variant FileNumber = FreeFile Open MY_FILENAME For Output As #FileNumber Print #FileNumber, "> ""AccReportMaster.txt"" rem/" Print #FileNumber, "for /R %%I in (""AccReport.txt"") do copy ""AccReportMaster.txt"" + ""%%~I"" ""AccReportMaster.txt"" /B" Print #FileNumber, "PAUSE" Close #FileNumber retVal = Shell(MY_FILENAME, vbNormalFocus) If retVal = 0 Then MsgBox "An Error Occured" Close #FileNumber End End If 'Added a 1 sec pause time as file was not closing in time before the code tried to delete it Application.Wait (Now + TimeValue("0:00:01")) Kill MY_FILENAME End Sub
Any help would be appreciated...