Jow
04-07-2008, 08:08 AM
I'm using this code within an excel macro to cycle through all workbooks in a directory and execute code within each one -
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
MyPath = "C:\Temp"
ChDir MyPath
TheFile = Dir("*.csv")
Do While TheFile <> ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
code to be executed here
wb.Close
TheFile = Dir
This code is obviously set up to look at a specific directory but the directories I want to use are constantly changing.
Is it possible to modify it so that it looks at the folder that is currently in use? So when I open a single excel file and i hit the macro, it will cycle through the other files within that same folder?
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
MyPath = "C:\Temp"
ChDir MyPath
TheFile = Dir("*.csv")
Do While TheFile <> ""
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
code to be executed here
wb.Close
TheFile = Dir
This code is obviously set up to look at a specific directory but the directories I want to use are constantly changing.
Is it possible to modify it so that it looks at the folder that is currently in use? So when I open a single excel file and i hit the macro, it will cycle through the other files within that same folder?