LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Update Directory Path in Code

Hello all, I'm attempting to run a macro to open all files in a
directory however, the directory changes from month to month (i.e.
from Apr to May and so on throughout the year. How can I point to the
new directory each month? This is the code I'm using now, but I want
to allow different users to run this monthly and they are not savy on
going in and editing my macro to change the directory path, and I'm
happy that thay can't. Appreciate any assistance with this macro.
Thank you, Ron

Sub Open_Files_In_A_Directory()
Dim fileList() As String
Dim fName As String
Dim fPath As String
Dim i As Integer
'define the directory to be searched for files
fPath = "T:\Budget Reports\NAPO\National Parts Operations\01 Apr\"


'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"
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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic directory path Newbie Excel Discussion (Misc queries) 1 April 24th 06 04:56 PM
Target directory & Path Param Excel Worksheet Functions 0 March 28th 06 01:52 AM
Need directory path without filename [email protected] Excel Programming 4 October 18th 05 08:56 PM
auto file path update when excel sheet moved to another directory. GNSBoy Excel Discussion (Misc queries) 1 August 31st 05 07:46 PM
Set The Directory to the Current WB Path Richy Excel Programming 2 February 29th 04 06:54 PM


All times are GMT +1. The time now is 12:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"