I am using the following code to create some files based on what is in a spreadsheet and am needing help on how to first create create a folder with the same name as the created file and put the created file in the folder that was created. Any help would be appreciated.
Code
Sub makeDHfiles()
'
Dim txtFileName As String
Dim fileBuffer As Integer
Dim lastRow As Long
Dim rowPtr As Long
Dim colPtr As Integer
Dim thePath As String
Dim lineTitle As String
lastRow = Range("A" & Rows.Count).End(xlUp).Row
If lastRow < 2 Then
Exit Sub ' no work to do
End If
thePath = Left(ThisWorkbook.FullName, _
InStrRev(ThisWorkbook.FullName, Application.PathSeparator))
For rowPtr = 2 To lastRow
txtFileName = CStr(Range("A" & rowPtr)) & ".dh"
fileBuffer = FreeFile()
Open thePath & txtFileName For Output As #fileBuffer
For colPtr = Range("A1").Column To Cells(1, Columns.Count).End(xlToLeft).Column
lineTitle = Trim(Cells(1, colPtr))
'add space characters to make 29 character string + :
lineTitle = lineTitle & String(29 - Len(lineTitle), " ") & ":"
Select Case colPtr
Case Range("E1").Column, Range("M1").Column
lineTitle = lineTitle & Format(Cells(rowPtr, colPtr), "##00")
Case Else
lineTitle = lineTitle & Cells(rowPtr, colPtr)
End Select
Print #fileBuffer, lineTitle
Next ' end colPtr loop
'close the text file
Close #fileBuffer
Next ' end rowPtr loop
MsgBox "Data Processing Completed", vbOKOnly + vbInformation, "Task Finished"
End Sub
Display More