VBA/Excel/Access/Word/File Path/Sequential Access Files
Create Sequential Access Files
File Access Modes with VBA
Access Mode Writing Data Reading Data
Sequential/Append Print#, Write# Input#, Input
Random Put Get
Binary Put, Write# Get, Input#, Input
Public Sub CreateSeqFile()
Dim filePath As String
Dim I As Integer
filePath = ActiveWorkbook.Path & "\MyHeaders.txt"
Open filePath For Output As #1
For I = 1 To 5
Write #1, Cells(1, I).Value
Next I
Close #1
End Sub
Read Sequential Access Files
Public Sub ReadSeqFile()
Dim filePath As String
Dim I As Integer
Dim myHeader As String
I = 1
filePath = ActiveWorkbook.Path & "\MyHeaders.txt"
Open filePath For Input As #1
Do While Not EOF(1)
Input #1, myHeader
Cells(1, I).Value = myHeader
I = I + 1
Loop
Close #1
End Sub
Write and read Sequential Access Files
Public Sub CreateSeqFile()
Dim filePath As String
Dim I As Integer
filePath = ActiveWorkbook.Path & "\SeqPhone.txt"
Open filePath For Output As #1
For I = 1 To 3
Write #1, Cells(I, "A").value, Cells(I, "B").value
Next I
Close #1
End Sub
Public Sub ReadSeqFile()
Dim filePath As String
Dim I As Integer
Dim theName As String
Dim theNumber As String
I = 1
filePath = ActiveWorkbook.Path & "\SeqPhone.txt"
Open filePath For Input As #1
Do While Not EOF(1)
Input #1, theName, theNumber
Cells(I, "A").value = theName
Cells(I, "B").value = theNumber
I = I + 1
Loop
Close #1
End Sub