Results 1 to 6 of 6

Help!! Output list of folders to particular cell

Threaded View

  1. #1
    Registered User
    Join Date
    07-19-2016
    Location
    london
    MS-Off Ver
    13
    Posts
    3

    Help!! Output list of folders to particular cell

    Hi, Need some help with my VBA as I'm new to all this.

    I have so far made some code which will look at a folder, that is selected in cell B1, and then create a list of all the folder names inside that folder and then turn all of the names into hyperlinks to the folder in question. The problem comes when I change folders which will happen every month.

    Is it possible to output this list of folders to a pre-defined cell that could be set in excel, say cell D1, so that when the folder is changed every month they will not overwrite the previous months folder names. I have tried this twice but failed each time.

    Thanks for any help in advance.

    Below is the code I have written so far.
    Sub Example1()
    
    Dim wb As Workbook
    Dim WS As Worksheet
    Dim objFSO As Object
    Dim objFolder As Object
    Dim objSubFolder As Object
    Dim i As Integer
    
        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
        Application.StatusBar = ""
    
        Set wb = ThisWorkbook
        Set wsControl = wb.Sheets("Control")
        Folder_Name = wsControl.Cells(1, 2)
        If Folder_Name = "" Then
            MsgBox "Path location is not entered. Please enter path"
            wsControl.Cells(1, 2).Select
            End
        End If
    'Create an instance of the FileSystemObject
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'Get the folder object
    Set objFolder = objFSO.GetFolder(Folder_Name)
    i = 1
    'loops through each file in the directory
    For Each objSubFolder In objFolder.subfolders
        'select cell
        Range(Cells(i + 1, 1), Cells(i + 1, 1)).Select
        'create hyperlink in selected cell
        ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
            objSubFolder.Path, _
            TextToDisplay:=objSubFolder.Name
        i = i + 1
    Next objSubFolder
    
        Columns("A:A").Select
        ActiveWorkbook.Worksheets("Control").sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Control").sort.SortFields.Add Key:=Range("A1"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Control").sort
            .SetRange Range("A2:A1000")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    End Sub
    Last edited by 6StringJazzer; 07-19-2016 at 03:16 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Code to create Folders and sub folders based on variable cell values
    By maxwell13 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-03-2015, 09:28 PM
  2. Replies: 2
    Last Post: 04-11-2015, 07:20 AM
  3. Replies: 1
    Last Post: 03-02-2015, 09:04 AM
  4. [SOLVED] Need folders copies into other folders based on excel list
    By swmatrixman in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-19-2013, 02:08 PM
  5. Replies: 0
    Last Post: 12-04-2012, 01:01 PM
  6. [SOLVED] Output list based on value in a cell
    By vegan@ucom.net in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2006, 10:30 AM
  7. Ooh .. Linking a list to a list to an output cell
    By StrawDog in forum Excel General
    Replies: 4
    Last Post: 08-22-2005, 05:05 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