Public Sub Data(WorkSheetName)
With Worksheets(WorkSheetName)
.UsedRange: .UsedRange.Select
End With
End Sub
Public Sub Data(WorkSheetName)
Dim xRange As Range
Dim fso As Object
Dim oFile As Object
Dim PathFile
PathFile = frmSettings.TextBox1.Text
If Right(PathFile, 1) <> "\" Then PathFile = PathFile & "\"
PathFile = PathFile & Application.ActiveWorkbook.Name & "." & WorkSheetName & ".txt"
With Worksheets(WorkSheetName)
Set xRange = .UsedRange
.UsedRange.Select
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFile = fso.CreateTextFile(PathFile)
For Each cell In xRange.Cells
p = p & cell.Value & frmSettings.ComboBox1.Value
If >>row changes<<
oFile.WriteLine p
p = ""
End If
Next
oFile.Close
Set fso = Nothing
Set oFile = Nothing
End Sub
FSO can't read Excel file, you got to use Excel objects to do that instead, use Excel.Application, Excel.Workbook, Excel.Worksheet instead.