+ Reply to Thread
Results 1 to 4 of 4

Multiple Subs in one Macro using the next free cell

Hybrid View

Whsperz Multiple Subs in one Macro... 06-16-2010, 07:46 PM
protonLeah Re: Multiple Subs in one... 06-16-2010, 10:33 PM
Whsperz Re: Multiple Subs in one... 06-17-2010, 09:45 PM
Whsperz Re: Multiple Subs in one... 06-18-2010, 04:14 PM
  1. #1
    Registered User
    Join Date
    06-16-2010
    Location
    Ketchikan AK
    MS-Off Ver
    Excel 2007
    Posts
    3

    Multiple Subs in one Macro using the next free cell

    What an excellent resource of a site. I have a multiple part question I could definitely use some assistance on. I am using a simple recursive folder listing macro that I would like to execute multiple times by changing the folder location in the macro. I haven't quite figured out how to do this, which leads me to here.

    Here's the code I would like to manipulate:
    Sub ListFiles1()
       Dim startRange As Range
     
       Set startRange = Sheet1.Range("A1")
      'Parent Directory - Change this to whichever directory you want to use
      ListFoldersAndInfo "Z:\TestList1", startRange, 0
    End Sub
     
    Sub ListFoldersAndInfo(foldername As String, Destination As Range, Level As Long)
      Dim FSO As Object
      Dim Folder As Object
      Dim R As Long
      Dim SubFolder As Object
      Dim Wks As Worksheet
     
        Set FSO = CreateObject("Scripting.FileSystemObject")
     
          Set Folder = FSO.GetFolder(foldername)
          Destination = Folder.Name
          Destination.IndentLevel = Level
     
          Destination.Offset(0, 1) = Folder.Size
          Set Destination = Destination.Offset(1, 0)
     
          For Each SubFolder In Folder.SubFolders
             ListFoldersAndInfo Folder.Path & "\" & SubFolder.Name, Destination, Level + 1
          Next SubFolder
     
        Set FSO = Nothing
     
    End Sub
    I can get this to run as multiple macros on different sheets by changing the Sub name, Sheet number and Folder location. However I would like this to look in 6 different locations and compile a single list, by using the next free cell after the first part of the macro is done. Any input on this would be great.

    Thanks.
    Last edited by Whsperz; 06-16-2010 at 07:53 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,964

    Re: Multiple Subs in one Macro using the next free cell.

    Not sure that I understand; but, it seems that you can use a loop:
    ' This macro assumes that you have created a sheet
    ' named "Folders" with column A holding the file name
    ' for instance,"Z:\TestList1", column B the start Range
    ' and column C the level
    
    
    Sub ListFiles1()
        Dim FolderCount     As Long, _
            TestFolder      As Range, _
            FOLDERLIST      As Worksheet
        
        Set FOLDERLIST = Sheets("folders")
        
        ' count the list of folders
        FolderCount = FOLDERLIST.Cells(Rows.Count, "A").End(xlUp).Row
        
        ' loop through the list
        For Each TestFolder In FOLDERLIST.Range("A1:A" & FolderCount)
            
            '                      folder name       start range                level
            ListFoldersAndInfo TestFolder.Value, TestFolder.Offset(0, 1), TestFolder.Offset(0, 2)
        Next TestFolder
            
    End Sub
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    06-16-2010
    Location
    Ketchikan AK
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Multiple Subs in one Macro using the next free cell

    Thanks protonLeah. I am not entirely sure that's what I am looking for. Unfortunately, I am so new at this aspect of macros, that I haven't a clue where to insert or to make it a seperate macro. Let me try to explain what is going on and you (or someone) might be able to guide me a little bit more.

    File lists consists of audio cds and dvds that (well anyone with young kids knows) I don't want to become harmed. The list of things has gotten overwhelming so I decided to create a storage of several drives to hold these. Since I reference them quite a bit, I thought compiling a list of them and using a mysql database to check from my iphone when I am at the store to see if I have it (always looking for bargains!) Let's just say that 4 drives consists of drive 1 (0-9, A-C), drive 2 (D-L), drive 3 (M-S), and drive 4 (T-Z). The macro I posted polls one drive (as I specify the location) per macro. I would like it to become one macro that it pulls the data into one sheet. I.E. Drive 1 finishes on A327, I would like Drive 2 to start adding content at A328 and continue to loop until it's done.

  4. #4
    Registered User
    Join Date
    06-16-2010
    Location
    Ketchikan AK
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Multiple Subs in one Macro using the next free cell

    Here's the post that the original code came from: http://www.excelforum.com/excel-prog...-in-excel.html

    6StringJazzer's solution was exactly what I was looking for when it came to listing the directories, recursively with indentation even. I just want it to work a little bit more than one time.

    I am still looking around trying to find some solution that will work for me in the long run.
    Thanks again to all that help guide me in the right direction.

+ 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