+ Reply to Thread
Results 1 to 7 of 7

Macro to open a workbook from an unknown file path

Hybrid View

  1. #1
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Macro to open a workbook from an unknown file path

    Sub FindInSubfoldersFileOpen()
       Dim StrFile As String, objFSO, destRow As Long
       Dim mainFolder, mySubFolder
       mFolder = Range("B2").Value ' initial folder
       fname = Range("B3").Value ' file name
       Set objFSO = CreateObject("Scripting.FileSystemObject")
       Set mainFolder = objFSO.GetFolder(mFolder)
       StrFile = Dir(mFolder & "\" & fname)
       If StrFile <> "" Then
          Workbooks.Open mFolder & "\" & StrFile
       Else
         For Each mySubFolder In mainFolder.SubFolders
           StrFile = Dir(mySubFolder & "\" & fname)
           If StrFile <> "" Then
              Workbooks.Open mySubFolder & "\" & StrFile
              Exit For
           End If
         Next
       End If
    End Sub
    If solved remember to mark Thread as solved

  2. #2
    Registered User
    Join Date
    11-27-2012
    Location
    australia
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Macro to open a workbook from an unknown file path

    Patel45. Still having trouble with this one.

    Macro seems to stop on Set objFSO = CreateObject("Scripting.FileSystemObject")

    Any suggestions why??

  3. #3
    Registered User
    Join Date
    11-27-2012
    Location
    australia
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Macro to open a workbook from an unknown file path

    Ahhh finally got it working. Seems issue is that it can search one subdirectory deep. Is it possible to modify it to search through say 4 tiers for subdirectories? Thanks for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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