Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 26th, 2004, 08:32 AM
Authorized User
 
Join Date: May 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Organise Work Sheet Respect to folder structure

Hi All

I have a assignment which is like this

I need to organise my excel sheets each sheet carrying the folder name.

Then in the corresponding sheet i need to place links for the files in the folder

I am able to place all the files as link in the worksheet but iam not able to organise the sheets according to the folder structure.

Can anyone help me how to read the subfolders inside a parent folder


Thanks in advance
__________________
Try Try Try Until You Succeed
 
Old October 26th, 2004, 08:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I guess you'll want to use the FileSystemObject.

You need to add a reference in your Project to something called "Microsoft Scripting Runtime" (find it under Tools -> References...). If you can't find it in the list it should be located somewhere along the lines of "C:\WINNT\System32\scrrun.dll".

Having referenced your project the following basic (& untested!) code should be pretty much what you want:

Code:
Sub test()

Dim scrFSO As Scripting.FileSystemObject
Dim scrMasterFolder As Scripting.Folder
Dim scrSubFolder As Scripting.Folder
Dim scrFile As Scripting.File

Dim ws As Worksheet

Const strMasterFilePath As String = "C:\Something"

    Set scrFSO = New Scripting.FileSystemObject
    Set scrMasterFolder = scrFSO.GetFolder(strMasterFilePath)

    For Each scrSubFolder In scrMasterFolder.SubFolders

        Set ws = ThisWorkbook.Worksheets.Add
        ws.Name = scrSubFolder.Name

        For Each scrFile In scrSubFolder.Files
            ' Put your links in ws
        Next scrFile

    Next scrSubFolder

End Sub
Hope this helps,
Maccas
 
Old October 26th, 2004, 08:54 AM
Authorized User
 
Join Date: May 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi maccas
     I tried this and is working fine.
Thanks a lot

Sri





Similar Threads
Thread Thread Starter Forum Replies Last Post
Still confused Folder structure eureka BOOK: ASP.NET Website Programming Problem-Design-Solution 5 September 14th, 2004 11:37 PM
Namespace vs. Folder Structure (Help Englere) groupmatch BOOK: ASP.NET Website Programming Problem-Design-Solution 14 September 8th, 2004 08:05 AM
C# folder and project structure organicglenn BOOK: ASP.NET Website Programming Problem-Design-Solution 3 September 7th, 2004 09:47 PM
thePhile (VB) file folder structure... jaspe BOOK: ASP.NET Website Programming Problem-Design-Solution 1 September 1st, 2004 08:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.