Search code examples
excelvbafilesystemobject

Error trying to open a csv using FileSystemObject: code runs and does nothing


I have the following code to open a file:

Sub prueba3()


Dim Obj As Object
Dim WB As Object

Set Obj = CreateObject("Scripting.filesystemobject")
Set WB = Obj.OpenTextFile("V:\evfilesce9i9\apps9\vbe9\dep4\KFTP\KFTP001D_FicherosCeca\30. RFSectorial\RF Sectorial 2018-05\QryCECARFSECTORIAL0239_EVO1_PRO_20180508205535.csv")


End Sub

I was expecting to get the file specified in Obj.Opentextifle() function to be opened, but the code runs and does nothing instead.

Could anyone clarify me if I'm misunderstanding how FileSystemObjectworks?

Thanks in advance


Solution

  • WB is now a TextStream object. You can do stuff with it like

    Debug.print(WB.ReadAll())
    

    This will print everything in the file to the console.

    As written your code opens the file and then nothing more since you don't ask it to do anything else. More here on the method you're using.