Attribute VB_Name = "Module2" Public Function TiedostoOlemassa( _ ByVal TstoNimi As String) As Boolean On Error GoTo Virhe: TiedostoOlemassa = Dir(TstoNimi) <> "" Exit Function Virhe: TiedostoOlemassa = False End Function Sub TestaaTiedostoOlemassa() MsgBox TiedostoOlemassa("D:\Data\Testi01.xls") End Sub Private Function KansioListaus(ByVal F As String) As String Dim OutStr As String Dim SR As String SR = Dir(F) OutStr = "" Do While SR <> "" OutStr = OutStr & SR & Chr(10) SR = Dir Loop KansioListaus = OutStr End Function Sub TestaaKansioListaus() MsgBox KansioListaus("D:\Data\*.xls") End Sub Sub TstoAvausDemo() Dim Tsto As String Tsto = "D:\Data\Testi.txt" Open Tsto For Input As #3 'Tarvittavat lukutoiminnot Close #3 End Sub Sub TiedostostaLukuDemo() Dim Tsto As String Dim Rivi As String Tsto = "D:\Data\Testi.txt" If Dir(Tsto) <> "" Then Open Tsto For Input As #7 Do While Not EOF(7) Line Input #7, LRivi Loop Close #7 End If End Sub Sub TiedostonKirjoitusDemo() Dim Tsto As String Dim Rivi As String If Dir("D:\Data\*.*") <> "" Then Tsto = "D:\Data\Testi.txt" Rivi = "Testirivi" Open Tsto For Output As #5 Write #5, Rivi Close #5 End If End Sub Sub TiedostoonLisaysDemo() Dim Tsto As String Dim Rivi As String Tsto = "D:\Data\Testi.txt" If Dir(Tsto) <> "" Then Open Tsto For Append As #6 Rivi = "Lisärivi" Write #6, Rivi Close #6 End If End Sub