Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello all, I got help from Rick Rothstein with this code. It works
great however, in the line fPath = "T:\Budget Reports\NAPO\National Parts Operations\01 " & _ Left(CurrentMonthAbbreviation, 3) & "\" When the month changes so does the leading 01. 01 Apr is the first month of our fiscal year. The directories range from 01 Apr to 12 Mar. Is there a way for the input box to ask for the full directory name (i.e. "02 May" and so on)? Thank you for your assistance, Ron Sub Open_Files_In_A_Directory() Dim fileList() As String Dim fName As String Dim fPath As String Dim i As Integer Dim CurrentMonthAbbreviation As String 'define the directory to be searched for files 'fPath = "T:\Budget Reports\NAPO\National Parts Operations\01 Apr \" CurrentMonthAbbreviation = InputBox("Enter the Month to Open" & Chr(13) & "Use the 3 Letter Abbreviation (i.e. Sep)") fPath = "T:\Budget Reports\NAPO\National Parts Operations\01 " & _ Left(CurrentMonthAbbreviation, 3) & "\" 'build a list of the files fName = Dir(fPath & "*.xls") While fName < "" 'add fname to the list i = i + 1 ReDim Preserve fileList(1 To i) fileList(i) = fName 'get next filename fName = Dir() Wend 'see if any files were found If i = 0 Then MsgBox "No Files Found!" & Chr(13) & "Are you sure the correct month was entered?" Exit Sub End If 'cycle through the list and open 'just those with the letter DP in the filename 'instr the following way is a case insensitive test For i = 1 To UBound(fileList) If InStr(1, fileList(i), "DP", 1) 0 Then Workbooks.Open fPath & fileList(i) End If Next End Sub |