Forum

How To Recognize Th...
 
Notifications
Clear all

How To Recognize The Name Of A Txt File. Without having to type it into the routine (.txt)

2 Posts
2 Users
0 Reactions
73 Views
(@a-maurizio)
Posts: 214
Reputable Member
Topic starter
 
Hello everyone from Maurizio
My new problem is this:
If we write this piece of code inside a routine:
 

Filename = Sheet.range ("A1"). Value Path = App.Path & " Data_TXT " & Filename & ".txt"

It should be deduced that in the cell of the excel sheet (A1) you can put the name to be 
given to the file; before it is saved.
And so far everything is ok

Now what I would like to know is this:
If by hypothesis I wanted to recover the contents of the file (TXT)
The only way I know to make the procedure understand that I want that type of file previously 
called this way and with those types of data inside it

I would write this:

Dim a As Long, line As String, arr () As String Dim Filename 'As String Dim Path 'As String Filename = Sheet.range ("A1"). Value Path = App.Path & " Data_TXT " & Filename & ".txt" Open Path For Input As # 1 Line Input # 1, line Close # 1 arr = Split (line, ",") For a = 1 To UBound (arr) List1.AddItem (arr (a)) Next a finish: End Sub

But if Always by hypothesis the I did not know the name I gave to the saved file.
Inside the procedure what should I write instead of:

Filename = Sheet.range ("A1"). Value
Path = App.Path & " Data_TXT " & This ______ Filename & ".txt"

That's all. Thank you
Greetings from A.Maurizio

 
Posted : 03/09/2022 4:11 am
(@catalinb)
Posts: 1937
Member Admin
 

You can use the FileSystemObject to loop through the txt files in that folder, until you find the one you want.

 
Posted : 06/09/2022 5:06 am
Share: