FSO (File Sytstem Object)
Add Library to use early binding
Option Explicit
Sub fso()
Dim fso As FileSystemObject
Dim name As String
Dim fldr As String
Dim rng As Range
Dim cell As Range
Dim ts As TextStream
Dim folder As folder
name = Format(Date, "mm-dd-yyyy")
fldr = "C:\Users\pc Admin\Desktop\" & name
Set fso = New FileSystemObject
If Not fso.FolderExists(fldr) Then
Set folder = fso.CreateFolder(fldr)
Else
End If
If Not fso.FileExists(fldr & "\My File.txt") Then
folder.CreateTextFile ("My File.txt")
End If
Set rng = Range("A1").CurrentRegion
Set ts = fso.OpenTextFile(fldr & "\My File.txt", ForWriting)
For Each cell In rng
ts.WriteLine cell
Next
End Sub
Add Library to use early binding
Option Explicit
Sub fso()
Dim fso As FileSystemObject
Dim name As String
Dim fldr As String
Dim rng As Range
Dim cell As Range
Dim ts As TextStream
Dim folder As folder
name = Format(Date, "mm-dd-yyyy")
fldr = "C:\Users\pc Admin\Desktop\" & name
Set fso = New FileSystemObject
If Not fso.FolderExists(fldr) Then
Set folder = fso.CreateFolder(fldr)
Else
End If
If Not fso.FileExists(fldr & "\My File.txt") Then
folder.CreateTextFile ("My File.txt")
End If
Set rng = Range("A1").CurrentRegion
Set ts = fso.OpenTextFile(fldr & "\My File.txt", ForWriting)
For Each cell In rng
ts.WriteLine cell
Next
End Sub
No comments:
Post a Comment