Hello, could someone please help?
I got a macro that retrieves data from many workbooks located in one folder. Since the workbooks may well change their location in a while, I searched for a code that would let me browse for destination folder. So I created a special purpose BrowseFolder function, then assigned it to my "Folder" variable. Now the macro pops up the browse window every time the "Folder" variable is mentioned further in the code.
Since I have many workbooks to refer to, the code refers to Folder many times making me select the same folder manually. Is there a way to get the macro to remember the folder I choose the first time it prompts me as all workbooks are and will be in the same directory?
I've only come up with an idea to write the selected folder path somewhere on a hidden sheet or in the inputs of my summary workbook and then make it default. But maybe a macro could store it somehow?
Also, I'd like the macro to check if the workbooks are in the default directory and only if they aren't in it, it would tell me "files are not found, please choose the directory", then I select the correct one (which becomes the new default folder where the macro will be first looking for the files next time), it gets that's where are the files and stops asking me all over again. Is it possible to write the checking-default-directory part with help of On Error statement?
Thanks for any help, here's part of the macro with all significant lines (sorry I might not be placing the code correctly, my first time copying it into the forum thread) :
Sub Status_Check()
Dim Folder
Dim FileName
Dim Refer
Sheets("Summary").Select
'links for formulas are formed, using "folder" variable:
For i = 8 To 91
ActiveSheet.Cells(i, 2).Select
Refer = ActiveCell.Value & "_qs.xlsx"
'here goes that special BrowseFolder function:
Folder = BrowseFolder
FileName = Folder & Refer
If Dir(FileName) <> "" Then
'now writing formulas in cells referring to :
ActiveSheet.Cells(i, 5).Select
'the next line contains Folder variable so it will prompt browse window as Folder = BrowseFunction
ActiveCell.Formula = "='" & Folder & "[" & Refer & "]" & "2013" & "'!" & "E$4"
ActiveSheet.Cells(i, 6).Select
'the window appears again...
ActiveCell.Formula = "='" & Folder & "[" & Refer & "]" & "2013" & "'!" & "F$4"
End If
Next i
'the code continues...
Bookmarks