M
maperalia
I wonder If somebody can help me with this matter.
I have a program that finds the “lst†files located under the directory
described on the cellâ€C3â€.
However, when I call these files I got all the files located under this
directory where sometimes more than 1000 files are found under this
directory. The fact is that I just need three or four of them.
I have been trying to make it run accordingly what I need (see macro below).
However, I could not make it work. I wonder if I can get just the files I
need. For example, if the cell “C3†has the description AAAA, cell “C5†has
the description G20, and the cell “C6†has the description 100. I want to
call the files under the directory AAAA which have the following files:
G20@100A
G20@100B
G20@100C
G20@100D
Sometimes, there are just three of them (A, B, and C) and sometimes are four
(A, B, C, and D).
Could you please check my program and let me know where I am failing because
I can not make it run.
Thanks in advance.
Maperalia
'***********************************************************************
‘Start Program
Sub List_lst_Files()
Dim FName As String
Dim r As Integer
Dim i As Long
Dim MyPath As String
Dim WO As String
Dim EXCAVATION As String
Dim depth As String
Dim Filename As String
Dim PostLetter As String
Const strFileType As String = "lst" '<<===== CHANGE
'With ActiveSheet.Columns(1)
'.Hyperlinks.Delete
'.ClearContents
'End With
Application.ScreenUpdating = False
WO = Worksheets("DEFAULTS").Range("C3")
'WO = Application.InputBox("Enter Work Order Number")
EXCAVATION = Worksheets("DEFAULTS").Range("C5")
depth = Worksheets("DEFAULTS").Range("C6")
PostLetter = A,B,C,D
Filename = "" & EXCAVATION & "& ""@"" &" & depth & """PostLetter"""
MyPath = "S:\GEOTEST\shears\" & WO & "\" & Filename & ".lst"
On Error Resume Next
Worksheets("List of lst Files").Delete
On Error GoTo 0
Application.DisplayAlerts = False
Worksheets.Add.Name = "List of lst Files"
Application.ScreenUpdating = False
r = 2
With Application.FileSearch
.NewSearch
.LookIn = MyPath
.SearchSubFolders = True
.Filename = "*." & strFileType
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
FName = Mid(.FoundFiles(i), 1)
Cells(r, 1) = Mid(FName, Len(MyPath) + 1, 255)
Application.ScreenUpdating = False
r = r + 1
Next i
End If
End With
'*************************************************************************************************
'FORMAT CELLS
Application.ScreenUpdating = False
ActiveSheet.Select
Columns("A:A").ColumnWidth = 20
Columns("A:A").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Dim myCell As Range
Dim myStr As String
Range("A1").Select
Set myCell = Worksheets("defaults").Range("C3")
myStr = "=""LST Files Found Under ""&" & myCell.Address(external:=True)
& "&"" Directory"""
ActiveCell.Formula = myStr
End Sub
‘End Program
'***********************************************************************
I have a program that finds the “lst†files located under the directory
described on the cellâ€C3â€.
However, when I call these files I got all the files located under this
directory where sometimes more than 1000 files are found under this
directory. The fact is that I just need three or four of them.
I have been trying to make it run accordingly what I need (see macro below).
However, I could not make it work. I wonder if I can get just the files I
need. For example, if the cell “C3†has the description AAAA, cell “C5†has
the description G20, and the cell “C6†has the description 100. I want to
call the files under the directory AAAA which have the following files:
G20@100A
G20@100B
G20@100C
G20@100D
Sometimes, there are just three of them (A, B, and C) and sometimes are four
(A, B, C, and D).
Could you please check my program and let me know where I am failing because
I can not make it run.
Thanks in advance.
Maperalia
'***********************************************************************
‘Start Program
Sub List_lst_Files()
Dim FName As String
Dim r As Integer
Dim i As Long
Dim MyPath As String
Dim WO As String
Dim EXCAVATION As String
Dim depth As String
Dim Filename As String
Dim PostLetter As String
Const strFileType As String = "lst" '<<===== CHANGE
'With ActiveSheet.Columns(1)
'.Hyperlinks.Delete
'.ClearContents
'End With
Application.ScreenUpdating = False
WO = Worksheets("DEFAULTS").Range("C3")
'WO = Application.InputBox("Enter Work Order Number")
EXCAVATION = Worksheets("DEFAULTS").Range("C5")
depth = Worksheets("DEFAULTS").Range("C6")
PostLetter = A,B,C,D
Filename = "" & EXCAVATION & "& ""@"" &" & depth & """PostLetter"""
MyPath = "S:\GEOTEST\shears\" & WO & "\" & Filename & ".lst"
On Error Resume Next
Worksheets("List of lst Files").Delete
On Error GoTo 0
Application.DisplayAlerts = False
Worksheets.Add.Name = "List of lst Files"
Application.ScreenUpdating = False
r = 2
With Application.FileSearch
.NewSearch
.LookIn = MyPath
.SearchSubFolders = True
.Filename = "*." & strFileType
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
FName = Mid(.FoundFiles(i), 1)
Cells(r, 1) = Mid(FName, Len(MyPath) + 1, 255)
Application.ScreenUpdating = False
r = r + 1
Next i
End If
End With
'*************************************************************************************************
'FORMAT CELLS
Application.ScreenUpdating = False
ActiveSheet.Select
Columns("A:A").ColumnWidth = 20
Columns("A:A").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Dim myCell As Range
Dim myStr As String
Range("A1").Select
Set myCell = Worksheets("defaults").Range("C3")
myStr = "=""LST Files Found Under ""&" & myCell.Address(external:=True)
& "&"" Directory"""
ActiveCell.Formula = myStr
End Sub
‘End Program
'***********************************************************************