process text files in folder (but avoid others in same folder)

dantheman9

Board Regular
Joined
Feb 5, 2011
Messages
175
Hi Im running a marco which will process and import text files from a folder.
Problem is, it that I have two types of text files in the folder, and only want to process one set.

the text files i want process are always named have the text string
'Splits Data' in, and then some varable string at the start, and sometimes data right after data like '(0001)'.

from using msoFolderPicker, is there anyway to direct only to text files that contain the string 'Splits Data' .

cheers

dan
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
could i edit the following like so to make it work?

Code:
 [COLOR=red]Const sFileSpec As String = "* "Split Data"*.txt"[/COLOR]      ' type of file to watch
  Const sAgeSelect As String = "00:00:30"  ' ignore files newer than this
  Dim sFileName As String
  Dim dFileStamp As Date
  Dim iFiles As Integer
  Dim iNewFiles As Integer
  Dim dLastFileProcessed As Date
  Dim dLatestFileDetected As Date
  
  
    Dim sh As Worksheet, sPath As String, sName As String
Dim r As Range, fName As String
Dim ShtName1 As String
Dim ShtName As String
Dim NewSht As Worksheet
Dim str As String
 Userform1.Fname1.Caption = LText
  Userform1.NFiles.Caption = "Looking in Folder Please wait...."
Application.ScreenUpdating = False
ShtName1 = "FULL RESULTS"
On Error Resume Next
Set sh = Sheets(ShtName1)
On Error GoTo 0
If sh Is Nothing Then
    Set NewSht1 = Worksheets.Add
    NewSht1.name = ShtName1
    Set sh = NewSht1
End If
ShtName = "TEMPS"
On Error Resume Next
Set NewSht = Sheets(ShtName)
On Error GoTo 0
If NewSht Is Nothing Then
    Set NewSht = Worksheets.Add
    NewSht.name = ShtName
End If
  
  
  dLastFileProcessed = lastDate
  'ThisWorkbook.Sheets("Sheet1").Range ("A1")
  
  [COLOR=red]sFileName = Dir(sFolder & sFileSpec)    (so hopefully it will only pick out text files with 'Split Data' in the file name here?)
[/COLOR]  Do While sFileName <> ""
    dFileStamp = FileDateTime(sFolder & sFileName)
    If dFileStamp > dLastFileProcessed And dFileStamp < Now() - TimeValue(sAgeSelect) Then
      iNewFiles = iNewFiles + 1
 
Upvote 0
Try:-
Code:
[COLOR=#ff0000]Const sFileSpec As String = "*Split Data*.txt"[/COLOR]
 
Upvote 0
thanks Ruddles,

cracked it with

Code:
[COLOR=#ff0000]Const sFileSpec As String = "*" & "Split Data" & "*.txt"[/COLOR]

cheers

dan
 
Upvote 0
OR:

Code:
Sub snb()
  Shell "cmd Dir C:\*Split Data*.txt /o-d /s /b >E:\files.txt"
  
  workbooks.add "E:\files.txt"
end sub
 
Upvote 0

Forum statistics

Threads
1,224,537
Messages
6,179,408
Members
452,912
Latest member
alicemil

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