Get Filepath which contain numbers (1 Viewer)

Trevor G

Registered User.
Local time
Today, 18:21
Joined
Oct 1, 2009
Messages
2,341
How can I refer to a filepath which contain text and numbers. What I am aiming to do is look through subfolders and return there name into excel, not file names. I have the code to look in a path as long as it is text but not including numbers. Example is as follows:

M:\Order 1999
M:\Order 2000
M:\Order 2001
M:\Order 2010

So I want to set the search path to pick up M:\Order plus the numbers.

Part of the code is using this

Call ListSubFoldersInFolder("M:\Order")
 

DCrake

Remembered
Local time
Today, 18:21
Joined
Jun 8, 2005
Messages
8,632
What is happening in ListSubFoldersInFolder ?
 

Trevor G

Registered User.
Local time
Today, 18:21
Joined
Oct 1, 2009
Messages
2,341
Hi David,

I am looking to use code to list all the folder & the subfolder names into an excel spreadsheet, the code is split into a number of functions, then I am calling the functions but I have to place in the path, but only want to use part of the path.

Example code is shown below:

List the Folder names Function

Function ListSubFoldersInFolder(ByRef strPath As String)
'Trevor G Dec 2010
Dim oFSO As Object
Dim oFolder As Object
Dim oSubFldr As Object
Dim N As Long
Application.ScreenUpdating = False
N = 1
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(strPath)
Cells(N, 1).Value = oFolder.Path
N = N + 1
For Each oSubFldr In oFolder.SubFolders
Cells(N, 1).Value = oSubFldr.Name
N = N + 1
Call ListSubFolders(oSubFldr, N)
Next
Application.ScreenUpdating = True
Set oFSO = Nothing
Set oFolder = Nothing
End Function

List the Sub Folder names

Function ListSubFolders(ByRef oParentFolder As Object, ByRef lngR As Long)
Dim oSubFolder As Object
For Each oSubFolder In oParentFolder.SubFolders
Cells(lngR, 2).Value = oSubFolder.Name
lngR = lngR + 1
ListSubFolders oSubFolder, lngR
Next 'oSubFolder
End Function

Call the functions

Sub MakeFolderList()
Sheets.Add
Call ListSubFoldersInFolder("M:\Order") 'Hope to include numbers
Call mcrFormula
End Sub
 

Users who are viewing this thread

Top Bottom