I need to txt file list in a specific folder, but my code does not work

Ongbey

New Member
Joined
Oct 16, 2018
Messages
31
Office Version
  1. 2013
Note : I am using Excel 2013

[FONT=&quot]Option Explicit[/FONT]

[FONT=&quot]Type FoundFileInfo[/FONT]
[FONT=&quot]sPath As String[/FONT]
[FONT=&quot]sName As String[/FONT]
[FONT=&quot]End Type[/FONT]
[FONT=&quot]------------------------------------------------------------------------------------------------------------------------------[/FONT]
[FONT=&quot]Function FindFiles(ByVal sPath As String, ByRef recFoundFiles() As FoundFileInfo, ByRef iFilesFound As Integer, _[/FONT]
[FONT=&quot]Optional ByVal sFileSpec As String = "*.*", Optional ByVal blIncludeSubFolders As Boolean = False) As Boolean[/FONT]
[FONT=&quot]End Function[/FONT]
[FONT=&quot]-----------------------------------------------------------------------------------------------------------------------------[/FONT]
[FONT=&quot]Public Sub Ara()[/FONT]
[FONT=&quot]Dim iFilesNum As Integer[/FONT]
[FONT=&quot]Dim iCount As Integer[/FONT]
[FONT=&quot]Dim recMyFiles() As FoundFileInfo[/FONT]
[FONT=&quot]Dim blFilesFound As Boolean[/FONT]

[FONT=&quot]blFilesFound = FindFiles("C:\Users\XXXXX\Desktop\New Folder", recMyFiles, iFilesNum, "*.txt?", True)[/FONT]
[FONT=&quot]If blFilesFound Then[/FONT]
[FONT=&quot]For iCount = 1 To iFilesNum[/FONT]
[FONT=&quot]With recMyFiles(iCount)[/FONT]
[FONT=&quot]MsgBox "Path:" & vbTab & .sPath & vbNewLine & "Name:" & vbTab & .sName, vbInformation, "Found Files"[/FONT]
[FONT=&quot]End With[/FONT]
[FONT=&quot]Next[/FONT]
[FONT=&quot]Else[/FONT]
[FONT=&quot]MsgBox "No file(s) found matching the specified file spec.", vbInformation, "File(s) not Found"[/FONT]
[FONT=&quot]End If[/FONT]

[FONT=&quot]End Sub[/FONT]
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Where are you hitting the issue in the code?

Code:
[COLOR=#141414]blFilesFound = FindFiles("C:\Users\XXXXX\Desktop\New Folder", recMyFiles, iFilesNum, "*.txt?", True)[/COLOR]

I could be misunderstanding the goal of the macro, but does this line need a \ following New Folder? (C:\Users\XXXXX\Desktop\New Folder\)
 
Upvote 0
Sorry, of course there is a "" at end of path.

I write the sub into a Module. Is it right? But code is still unsuccessful.
 
Upvote 0
Sorry, of course there is a "" at end of path.

I write the sub into a Module. Is it right? But code is still unsuccessful.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top