All,
I have worked on this code for most of the afternoon and I was wondering if anyone could look at this and recommend ANY ways of making this code better/faster. Unfortunatly, the files I am extracting are on a shared server which could produce a slower responce time... with that said, I would like to have the best code possible. There are NO errors or problems... this code works. Any suggestions, are greatly appreciated.
[VBA]
'-------------------------------------------------------------
Function GetFileName(Strpath As String)
Dim iStart As Integer
Dim Strchar As String
For iStart = Len(Strpath) To 1 Step -1
Strchar = Mid(Strpath, iStart, 1)
If Strchar = "\" Then Exit For
Next iStart
GetFileName = Mid(Strpath, iStart + 1, Len(Strpath) - iStart)
End Function
'-------------------------------------------------------------
Sub Button1_Click()
Dim vName As Variant
Dim pFile As Integer, aFile As Integer, x As Integer, C As Integer
Dim pDirectory As String, aDirectory As String
'Set path for files (Preliminary and Authorized)
pDirectory = "S:\Phil\Forms - Issued\LDF\" & vName(x) & "\Preliminary"
aDirectory = "S:\Phil\Forms - Issued\LDF\" & vName(x) & "\Authorized"
Sheets("Data Sheet").Select
Range("A:L").Clear
Range("A2").Select
vName = Array("Dave Dittelman", "Dick Towne", "Ed Candelaria", "Rick Nehls", _
"Ryan Tesiero", "Display Services")
For x = LBound(vName) To UBound(vName)
'Lists all the files in a Preliminary state
ActiveCell.Offset(0, C).Value = vName(x) & " - Preliminary"
With Application.FileSearch
.LookIn = pDirectory
.Execute
For pFile = 1 To .FoundFiles.Count
ActiveCell.Offset((pFile + 1), C).Value = GetFileName(.FoundFiles(pFile))
Next pFile
End With
'Move to next column, and list the files in an Autorized state
ActiveCell.Offset(0, C + 1).Value = vName(x) & " - Authorized"
With Application.FileSearch
.LookIn = aDirectory
.Execute
For aFile = 1 To .FoundFiles.Count
ActiveCell.Offset((aFile + 1), C + 1).Value = GetFileName(.FoundFiles(aFile))
Next aFile
End With
Let C = C + 1 'Increase C to goto next column
Next x
Range("A2:L2").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Interior.ColorIndex = 1
.Interior.Pattern = xlSolid
.Font.Name = "arial"
.Font.Size = 10
.Font.Bold = True
.Font.ColorIndex = 2
End With
Columns("A:N").EntireColumn.AutoFit
Range("A1").Select
End Sub
[/VBA]
Thanks, Phil