M
Mr. GetRight
Ok. Not sure what I am doing wrong so i will start off with what I want to do.
Below is my code that is to go out to location of workbook, look for other
workbooks saved in subfolders,save their location, then manager's name, and
year from the file name to an array. ex location: C:\Documents and
Settings\Guest\Desktop\cand be deleted\2008 CBT Tracker for DoeJane.xls
Problems:
1 I am getting an complier error for line starting off
"ListbManagerNameSelection". It is for the array. I was trying to make it
global because I will reuse them on another part of the workbook.
I removed that part out to make sure the rest would work but when it
attempts to save data to the first array i receive run time error 424. what
am i doing wrong?
Private Sub UserForm_Activate()
If (NumFiles = LoadFileDate(CBTfilesArray)) = True Then ' Goes to This
Workbook code screen and loads manger name, year, file path\name
For count = 1 To NumFiles
ListbManagerNameSelection.List = CBTfilesArray.ManagerName
'Output manager's name in list box to be selected by user
Next count
Else
MsgBox "There were no files found."
End If
End Sub
'Code below is saved in Module
Option Explicit
Public CBTfilesArray() As Variant
Type CBTfilesArray
ManagerName As String
CBTtrackingYear As Integer
CBTtrackerFileName As String
End Type
Function LoadFileDate()
Dim fs As Object
Dim i As Integer
Dim Mypath As String
Mypath = ActiveWorkbook.Path
Set fs = Application.FileSearch
MsgBox Mypath
With fs
'Change below to give the name of the Directory you want to search
.LookIn = Mypath & "\"
.SearchSubFolders = True
.FileName = "*.xls"
If .Execute() > 0 Then
For i = 1 To .FoundFiles.count
ReDim Preserve CBTfilesArray(i - 1)
CBTfilesArray(i - 1).ManagerName = Mid(.FoundFiles(i),
InStrRev(.FoundFiles(i), " ") + 1) 'Get Manager Name and adds it to array
CBTfilesArray(i - 1).CBTtrackingYear = (Mid(.FoundFiles(i),
InStrRev(.FoundFiles(i), "\") + 1, 4)) ' Get the year of the CTB Tracker
CBTfilesArray(i - 1).FileName = (.FoundFiles(i)) 'Get file
address and addes to array
Next i
LoadFileDate = .FoundFiles.count
Else
LoadFileDate = False
End If
End With
If LoadFileDate Then
MsgBox (LoadFileDate + 1) & " files found. Managers are " &
CBTfilesArray(1).ManagerName
Else
MsgBox "No files were loaded into Array"
End If
End Function
Below is my code that is to go out to location of workbook, look for other
workbooks saved in subfolders,save their location, then manager's name, and
year from the file name to an array. ex location: C:\Documents and
Settings\Guest\Desktop\cand be deleted\2008 CBT Tracker for DoeJane.xls
Problems:
1 I am getting an complier error for line starting off
"ListbManagerNameSelection". It is for the array. I was trying to make it
global because I will reuse them on another part of the workbook.
I removed that part out to make sure the rest would work but when it
attempts to save data to the first array i receive run time error 424. what
am i doing wrong?
Private Sub UserForm_Activate()
If (NumFiles = LoadFileDate(CBTfilesArray)) = True Then ' Goes to This
Workbook code screen and loads manger name, year, file path\name
For count = 1 To NumFiles
ListbManagerNameSelection.List = CBTfilesArray.ManagerName
'Output manager's name in list box to be selected by user
Next count
Else
MsgBox "There were no files found."
End If
End Sub
'Code below is saved in Module
Option Explicit
Public CBTfilesArray() As Variant
Type CBTfilesArray
ManagerName As String
CBTtrackingYear As Integer
CBTtrackerFileName As String
End Type
Function LoadFileDate()
Dim fs As Object
Dim i As Integer
Dim Mypath As String
Mypath = ActiveWorkbook.Path
Set fs = Application.FileSearch
MsgBox Mypath
With fs
'Change below to give the name of the Directory you want to search
.LookIn = Mypath & "\"
.SearchSubFolders = True
.FileName = "*.xls"
If .Execute() > 0 Then
For i = 1 To .FoundFiles.count
ReDim Preserve CBTfilesArray(i - 1)
CBTfilesArray(i - 1).ManagerName = Mid(.FoundFiles(i),
InStrRev(.FoundFiles(i), " ") + 1) 'Get Manager Name and adds it to array
CBTfilesArray(i - 1).CBTtrackingYear = (Mid(.FoundFiles(i),
InStrRev(.FoundFiles(i), "\") + 1, 4)) ' Get the year of the CTB Tracker
CBTfilesArray(i - 1).FileName = (.FoundFiles(i)) 'Get file
address and addes to array
Next i
LoadFileDate = .FoundFiles.count
Else
LoadFileDate = False
End If
End With
If LoadFileDate Then
MsgBox (LoadFileDate + 1) & " files found. Managers are " &
CBTfilesArray(1).ManagerName
Else
MsgBox "No files were loaded into Array"
End If
End Function