STEVEMILLS04
Board Regular
- Joined
- Oct 8, 2009
- Messages
- 113
Ok, an hour of searching and bending my mind isn't doing the trick, so I turn to you MrExcel experts.
I am doing a what-should-be-simple SPLIT on a filename, code below. I get the following error "Subscript out of range", which I believe is because there is nothing in the (1) position in the array?
Filenames are as follows: 12300-AddressChange.pdf, 12921-Promotion.pdf, 12929-RateIncrease.pdf
When I print the filename, it shows accurately "12300-AddressChange.pdf". When I print splitName(0) it's accurate, "12300". When I add splitName(1) it errors out.
I believe it has something to do with the fileName, as when I split the string instead of the variable, it works just fine. For example,
I just don't know why.
I am doing a what-should-be-simple SPLIT on a filename, code below. I get the following error "Subscript out of range", which I believe is because there is nothing in the (1) position in the array?
Filenames are as follows: 12300-AddressChange.pdf, 12921-Promotion.pdf, 12929-RateIncrease.pdf
When I print the filename, it shows accurately "12300-AddressChange.pdf". When I print splitName(0) it's accurate, "12300". When I add splitName(1) it errors out.
I believe it has something to do with the fileName, as when I split the string instead of the variable, it works just fine. For example,
Code:
splitName = Split("12300-AddressChange.pdf", "-")
I just don't know why.
Code:
Sub loopAllSubFolderSelectStartDirector()
'Another Macro must call LoopAllSubFolders Macro to start procedure
Call LoopAllSubFolders("R:\Human Resources Private\Employee Files Dayforce\To Be Filed\")
End Sub
Sub LoopAllSubFolders(ByVal folderPath As String)
Dim fileName As String
Dim fullFilePath As String
Dim numFolders As Long
Dim folders() As String
Dim i As Long
Dim lPosition As Long
Dim eeNum As String
Dim parentFolder As String
Dim splitName() As String
Dim colF As String
If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
fileName = Dir(folderPath & "*.*", vbDirectory)
While Len(fileName) <> 0
If Left(fileName, 1) <> "." Then
fullFilePath = folderPath & fileName
splitName = Split(fileName, "-")
eeNum = splitName(0)
colF = splitName(1)
If (GetAttr(fullFilePath) And vbDirectory) = vbDirectory Then
ReDim Preserve folders(0 To numFolders) As String
folders(numFolders) = fullFilePath
numFolders = numFolders + 1
Else
'Insert the actions to be performed on each file
'This example will print the ee# then the file name to the immediate window
Debug.Print fileName
Debug.Print "eeNum = " & eeNum & ", colF = " & colF
End If
End If
fileName = Dir()
Wend
For i = 0 To numFolders - 1
LoopAllSubFolders folders(i)
Next i
End Sub