Option Explicit
Sub CreateBatchFiles()
Dim rIn As Range
Dim lR As Long
Set rIn = Range("A1").CurrentRegion
For lR = 1 To rIn.Rows.Count ' <<<<<< If A1 is header row, then change lR= 1 to LR=2
data_to_text_file rIn.Cells(lR, 1), rIn.Cells(lR, 2), rIn.Cells(lR, 3)
Next lR
End Sub
Private Sub data_to_text_file(sPath As String, sFName As String, sCmd As String)
Dim iTextFile As Integer
Dim sMyFile As String
'check if path ends with path separator
sPath = CheckPath(sPath)
'check if filename ends with .BAT
sFName = CheckFName(sFName)
'path to the text file
sMyFile = sPath & sFName
'define FreeFile to the variable file number
iTextFile = FreeFile
'using append command to add text to the end of the file
Open sMyFile For Output As iTextFile
'add data to the text file
Print #iTextFile, sCmd
'close command to close the text file after adding data
Close #iTextFile
End Sub
Private Function CheckPath(sPath As String) As String
Dim sSep As String
If sPath Like "*/*" Then
sSep = "/"
Else
sSep = "\"
End If
If Not Right(sPath, 1) Like sSep Then
sPath = sPath & sSep
End If
CheckPath = sPath
End Function
Private Function CheckFName(sFName As String) As String
If Not sFName Like "*.bat" Then
sFName = sFName & ".bat"
End If
CheckFName = sFName
End Function