Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Not able to Open Text file and search

  Asked By: Ayden    Date: Sep 03    Category: MS Office    Views: 886
  

Please find my problem regarding accessing text file below:

There are set of text (.txt format) files in a folder. I need to
open each file and search for a string in each file. I am to create
an instance to folder and get the file but not able to open them.
Please suggest on the same.

Sub Filetext1()
Dim x As Object
Set x = CreateObject("Scripting.FilesystemObject")
Set y = x.Getfolder("C:\AS400 Sessions")
For Each file In y.Files
name1 = file.Name 'I am getting the name correctly

'I need to open each file and search for text here


Next
MsgBox (Count)
End Sub

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Frederik Jones     Answered On: Sep 03

From a quick Google search, it appears that it is the FileSystemObject that
has the open  method. I.e. something like

Dim FileStream As Object
Set FileStream = x.opentextfile("C:\Batch\" & file.Name)

However, there might be other ways too.

 
Answer #2    Answered By: Niran Jainukul     Answered On: Sep 03

as long as you have the full file  name you don't
actually need to use the filesystem object.

Try googling or using the help and look for "LineInput".

 
Didn't find what you were looking for? Find more on Not able to Open Text file and search Or get search suggestion and latest updates.




Tagged: