Hi,
I am looking for a way to create a list of empty .txt files based that are based on the values of a range of cells.
Here is what I have but no file is ever created.
Please note that I am a beginner in VBA and tried to adapt some code I found on the web.
Thanks in advance for any advice/suggestions.
Lex.
Sub MakeFolders()
Dim Rng As Range
Dim maxRows, maxCols, r, c As Integer
Dim filename As String
Set Rng = Selection
maxRows = Rng.Rows.Count
maxCols = Rng.Columns.Count
For c = 1 To maxCols
r = 1
Do While r <= maxRows
If Len(Dir(ActiveWorkbook.Path & "\" & Rng(r, c), vbDirectory)) = 0 Then
'MkDir (ActiveWorkbook.Path & "\" & Rng(r, c)) - THE CODE WORKS FOR CREATING FOLDER NAMES
'BUT WHEN I TRY TO ADAPT THE CODE AND USE THE SAME LOGIC FOR CREATNG FILES NO FILE GETS CREATED
filename = Rng(r, c) & ".txt"
'MsgBox filename I USED THIS TO CHECK IF THE FILENAME IS CORRECT
Open ActiveWorkbook.Path & filename For Output As r
Close r
On Error Resume Next
End If
r = r + 1
Loop
Next c
End Sub
I am looking for a way to create a list of empty .txt files based that are based on the values of a range of cells.
Here is what I have but no file is ever created.
Please note that I am a beginner in VBA and tried to adapt some code I found on the web.
Thanks in advance for any advice/suggestions.
Lex.
Sub MakeFolders()
Dim Rng As Range
Dim maxRows, maxCols, r, c As Integer
Dim filename As String
Set Rng = Selection
maxRows = Rng.Rows.Count
maxCols = Rng.Columns.Count
For c = 1 To maxCols
r = 1
Do While r <= maxRows
If Len(Dir(ActiveWorkbook.Path & "\" & Rng(r, c), vbDirectory)) = 0 Then
'MkDir (ActiveWorkbook.Path & "\" & Rng(r, c)) - THE CODE WORKS FOR CREATING FOLDER NAMES
'BUT WHEN I TRY TO ADAPT THE CODE AND USE THE SAME LOGIC FOR CREATNG FILES NO FILE GETS CREATED
filename = Rng(r, c) & ".txt"
'MsgBox filename I USED THIS TO CHECK IF THE FILENAME IS CORRECT
Open ActiveWorkbook.Path & filename For Output As r
Close r
On Error Resume Next
End If
r = r + 1
Loop
Next c
End Sub