+ Reply to Thread
Results 1 to 3 of 3

Get browse folder pop-up window to remember selected directory

  1. #1
    Registered User
    Join Date
    08-30-2013
    Location
    Moscow, Russia
    MS-Off Ver
    Excel 2007
    Posts
    4

    Get browse folder pop-up window to remember selected directory

    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...

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Get browse folder pop-up window to remember selected directory

    Move the browsefolder bit outside the loop:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-30-2013
    Location
    Moscow, Russia
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Get browse folder pop-up window to remember selected directory

    yudlugar, thanks a lot, that helped me!

    However, now I realize that the macro would ask the user for the location of files everytime it's started. To avoid that, I created a code that would first look at a folder specified in some certain cell in my workbook, then check if it exists on the computer, and in case it doesn't, prompt the user to set a new location. It's not working though, I've step-tested it and it looks like it just doesn't catch the new folder path and won't write it down in the cell. Can you tell me what's wrong? Below are the code and the function it refers to.

    Sub Folder_Picker()

    Dim Folder As String
    Dim FolderPath As String

    FolderPath = Worksheets("Abc").Cells(3, 7).Value
    If Dir(FolderPath, vbDirectory) = "" Then
    Sheets("Abc").Select
    Cells(3, 7).Value = BrowseFolder("Please select the folder")
    End If
    Folder = Worksheets("Abc").Cells(3, 7).Value

    End Sub




    Function BrowseFolder(Title As String, _
    Optional InitialFolder As String = vbNullString, _
    Optional InitialView As Office.MsoFileDialogView = _
    msoFileDialogViewList) As String
    Dim V As Variant
    With Application.FileDialog(msoFileDialogFolderPicker)
    .Title = Title
    .Show
    End With
    BrowseFolder = CStr(V)
    End Function

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro to browse for an excel file in a specfic directory
    By lsteinbach in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-27-2012, 12:45 PM
  2. HOW: Open Browse Window, Select File, Copy Filename Selected.
    By monak83 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-19-2012, 03:43 AM
  3. Browse for directory (with custom default option)
    By zeke varg in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-18-2010, 01:27 PM
  4. Browse for folder
    By Steph in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-08-2005, 12:55 PM
  5. directory browse...
    By mark in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-11-2005, 02:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1