Sub Create_Files() 'ActiveSheet should be refer as following: 'Column A: File Name 'Column B: Extention file 'Column C content Dim i As Long Dim fileName As String Dim folder As String Dim fNum As Long Dim lr As Long Dim ws As Worksheet Dim iRet As Integer Dim strPrompt As String Dim strTitle As String ' Promt strPrompt = "Make sure that you have reported the following Reference activesheet as following:" _ & "Column A: file Name" _ & "Column B: Extention file" & vbCr & "OK?" ' Dialog's Title strTitle = "Title" 'Display MessageBox iRet = MsgBox(strPrompt, vbQuestion + vbYesNo, strTitle) ' Check pressed button If iRet = vbNo Then MsgBox "The code will exit now.", vbExclamation, "Action Cancelled By You!" Exit Sub End If lr = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).row folder = "" 'Change to folderpicker 'With Application.FileDialog(msoFileDialogFolderPicker) '.Title = sTitle '.ButtonName = sButton '.InitialFileName = sStartFrom 'If .Show = -1 Then ' if OK is pressed 'sFolder = .SelectedItems(1) 'End If 'End With 'If sFolder <> "" Then ' if a file was chosen 'MsgBox sFolder Set ws = ActiveSheet If Len(Dir(folder & Format(Now, "yyyy_mm_dd_hh") & "\", vbDirectory)) = 0 Then MkDir folder & Format(Now, "yyyy_mm_dd_hh") & "\" End If folder2 = folder & Format(Now, "yyyy_mm_dd_hh") & "\" 'REMEMBER END BACKSLASH For i = 2 To lr fileName = folder2 & ws.Cells(i, "A").Value & ws.Cells(i, "B").Value fNum = FreeFile Open fileName For Output As #fNum Print #fNum, ws.Cells(i, "C").Value Close #fNum Next MsgBox "Files have been created at " & folder2 End Sub
From novice to tech pro — start learning today.