Gets the desired record from the file and writes the fields to the worksheet. : Random Access Files « File Path « VBA / Excel / Access / Word






Gets the desired record from the file and writes the fields to the worksheet.

 
Private Type Employee
     empID As String * 8
     empName As String * 20
     empAge As Integer
     empStatus As String * 10
     empSalaryClass As String * 1
End Type
 
Sub GetEmployeeInfo()
    Dim empData As Employee
    Dim filePath As String
    filePath = ActiveWorkbook.Path & "\Employees.txt"
    Open filePath For Random As #1 Len = Len(empData)
        Get #1, recNum, empData
        Cells(2, "A").Value = empData.empID
        Cells(2, "B").Value = empData.empName
        Cells(2, "C").Value = empData.empAge
        Cells(2, "D").Value = empData.empStatus
        Cells(2, "E").Value = empData.empSalaryClass
    Close #1
End Sub

 








Related examples in the same category

1.Random Access Files
2.Use Random Access Files to save a user defined data type