Text Files and File Dialog
Sub WriteFile()
Dim dDate As Date
Dim sCustomer As String
Dim sProduct As String
Dim dPrice As Double
Dim sFName As String 'Path and name of text file
Dim iFNumber As Integer 'File number
Dim lRow As Long 'Row number in worksheet
sFName = "C:\Sales.txt"
iFNumber = FreeFile
Open sFName For Output As #iFNumber
lRow = 2
Do
With Sheet1
dDate = .cells(lRow, 1)
sCustomer = .cells(lRow, 2)
sProduct = .cells(lRow, 4)
dPrice = .cells(lRow, 6)
End With
Write #iFNumber, dDate, sCustomer, sProduct, dPrice
lRow = lRow + 1
Loop Until IsEmpty(Sheet1.cells(lRow, 1))
Close #iFNumber
End Sub
Related examples in the same category