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

Ongbey

New Member
Joined
Oct 16, 2018
Messages
38
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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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